简体   繁体   中英

Show div when page scroll down in jquery

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.

You may try this similar case:

http://jsfiddle.net/j7r27/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM