滚动条偏移情况来显示div内容。

下面的栗子是:当滚动条距顶部300内显示tree01内容,距顶部600显示tree02内容,距顶部900显示tree03内容。

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
    $(document).scroll(function(){
        var top = $(document).scrollTop();
        if(top < 300)
            $(".tree01").show();
        else if(top < 600)
            $(".tree02").show();
        else if(top < 900)
            $(".tree03").show();
    });
});
</script>
<div style="height:300px;"></div>
<div class="tree01" style="width:300px;height:300px;background-color:red;display:none;"></div>
<div class="tree02" style="width:300px;height:300px;background-color:blue;display:none;"></div>
<div class="tree03" style="width:300px;height:300px;background-color:green;display:none;"></div>
<div style="height:3000px;"></div>

非特殊说明,本博所有文章均为博主原创。

如若转载,请注明出处:http://www.notemi.cn/jQuery-1.html

添加新评论

icon_question.pngicon_razz.pngicon_sad.pngicon_evil.pngicon_exclaim.pngicon_smile.pngicon_redface.pngicon_biggrin.pngicon_surprised.pngicon_eek.pngicon_confused.pngicon_cool.pngicon_lol.pngicon_mad.pngicon_twisted.pngicon_rolleyes.pngicon_wink.pngicon_idea.pngicon_arrow.pngicon_neutral.pngicon_cry.pngicon_mrgreen.png

21 + 23 =


已有 2 条评论
    Jul 6, 2016 回复

    jquery判断滚动条与头部距离。


    Jul 7, 2015 回复

    学习一下