最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show div when page scroll down in jquery - Stack Overflow

programmeradmin0浏览0评论

I have this HTML code

HTML

<div id="d1"></div>
<div id="d2"></div>
<div id="d3"></div>
<div id="d4"></div>
<div id="d5"></div>

and this CSS code

CSS

#d1, #d2, #d3, #d4, #d5{ float:left; height:500px; width:200px; display:none;}

Script:

<script>
        $(document).ready(function() {
            $(window).scroll(function() {
                if ($("#d2").height() <= ($(window).height() + $(window).scrollTop())) {
                    $("#d1").css("display","block");
                }else {
                    $("#d1").css("display","none");
                }
            });
        });
    </script>

Question: When I scroll page down each div display one by one. When scroller reach at "#d2" the div "#d1" should be displayed, When scroller reach at "#d3" div "#d2" should be displayed.... and when scroller reach at the end of page "#d5" should be displayed.

I have this HTML code

HTML

<div id="d1"></div>
<div id="d2"></div>
<div id="d3"></div>
<div id="d4"></div>
<div id="d5"></div>

and this CSS code

CSS

#d1, #d2, #d3, #d4, #d5{ float:left; height:500px; width:200px; display:none;}

Script:

<script>
        $(document).ready(function() {
            $(window).scroll(function() {
                if ($("#d2").height() <= ($(window).height() + $(window).scrollTop())) {
                    $("#d1").css("display","block");
                }else {
                    $("#d1").css("display","none");
                }
            });
        });
    </script>

Question: When I scroll page down each div display one by one. When scroller reach at "#d2" the div "#d1" should be displayed, When scroller reach at "#d3" div "#d2" should be displayed.... and when scroller reach at the end of page "#d5" should be displayed.

Share Improve this question edited May 7, 2014 at 11:03 user3190238 asked May 7, 2014 at 10:48 user3190238user3190238 431 gold badge2 silver badges6 bronze badges 3
  • Please post the code you have attempted to write yourself to solve this problem. Also, if a div is offscreen, why does it need to be hidden/displayed? – Rory McCrossan Commented May 7, 2014 at 10:49
  • 1 There are many plugins and snippet available for that, google it – A. Wolff Commented May 7, 2014 at 10:52
  • you could try a jquery plug in imakewebthings./jquery-waypoints – Adween Commented May 7, 2014 at 11:08
Add a ment  | 

1 Answer 1

Reset to default 2

You may try this similar case:

http://jsfiddle/j7r27/

$(window).scroll(function() {
$("div").each( function() {
    if( $(window).scrollTop() > $(this).offset().top - 100 ) {
        $(this).css('opacity',1);
    } else {
        $(this).css('opacity',0);
    }
}); 
});
发布评论

评论列表(0)

  1. 暂无评论