以下是示例:http://jsfiddle.net/NH6Km/2/
JQUERY:
$(function(){
$(window).scroll(function() {
if ($(window).scrollTop() > 50) {
('body,html').animate({ scrollTop:
$('#second').offset().top }, 1500);
}
});
})
HTML:
<div id="first"></div>
<div id="second"></div>
CSS:
#first{
position:absolute;
width:100%; height:100%;
background:blue;
}
#second{
position:absolute;
top:100%;
width:100%; height:100%;
background:yellow;
}
答案 0 :(得分:0)
正如@thecodedestroyer所说,你可以使用滚动事件做这样的事情:
var currentDiv = "#first";
var divArray = ["#first", "#second", "#third", "#fourth"];
$(window).on("scroll", function (e) {
var ix = divArray.indexOf(currentDiv);
if (ix >= 0) {
if (window.pageYOffset > $(currentDiv).offset().top) {
currentDiv = divArray[(ix + 1) % currentDiv.length];
} else if (window.pageYOffset < $(currentDiv).offset().top) {
currentDiv = divArray[(ix - 1) % currentDiv.length];
}
$("body, html").animate({
scrollTop: $(currentDiv).offset().top
}, 0);
e.preventDefault();
return false;
}
});
这是一个测试: http://jsfiddle.net/cxJQE/
答案 1 :(得分:-1)