请帮助我解决以下情况
我有 3 个页面,当滚动到达第二页时,用户滚动页面,它必须找到特定的 ID,然后触发一个函数。一旦第三页开始,另一个函数就会触发。
根据要求我不应该使用任何插件
<script>
$(window).on("scroll", function() {
var offset = $("#two").offset();
var posY = offset.top - $(window).scrollTop();
if (offset.top + $("#two").height() > $(window).scrollTop()) {
apply();
} else {
remove();
}
</script>
<body>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
</body>
有一个很棒的插件可以做到这一点,称为WAYPOINT https://github.com/imakewebthings/jquery-waypoints
我已经设置了一个例子jsfiddle 看看 http://jsfiddle.net/mGtbK/
HTML
<div class="first"></div>
<div class="second"></div>
CSS
.first {
background:green;
height: 600px;
width:100%;
}
.second {
background:red;
height: 600px;
width:100%;
}
JS
$('.second').waypoint(function() {
alert('You have scrolled to an entry.');
}, {
offset: '100%'
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)