【发布时间】:2014-08-30 20:47:01
【问题描述】:
我将有许多高度为 100vh 的 div,例如 #pg1、#pg2 堆叠在一起。然后,如果我向下滚动一点点或按下箭头按钮(链接带有将在右上角的图像),它会将另一个 div 定位为平滑地占据页面的 100%。
编辑:像这样(不完全是):http://jsfiddle.net/wofbbzjy/
<div id="pg1">Teste</div>
<div id="pg2">Teste</div>
<div id="pg3">Teste</div>
$(document).ready(function(){
$(window).scroll(function(){
var content_height = $(document).height();
var content_scroll_pos = $(window).scrollTop();
var percentage_value = content_scroll_pos * 100 / content_height;
if(percentage_value >= 0){
$('html,body').animate({
scrollTop: $('#pg2').position().top
}, 1000);
return false;
}
});
});
#pg1, #pg2 {
background-color: grey;
height: 100vh;
width: 100%;
}
#pg2 {
background-color: yellow;
}
#pg3 {
background-color: black;
}
【问题讨论】:
-
那么问题是什么?
-
我不知道如何设置 jquery 来做我想做的事
-
我试过这样的东西,但这不是我想要的jsfiddle.net/wofbbzjy
-
@user3417825 如果不在您的问题中包含代码,则不允许直接链接到 jsFiddle 是有原因的。我已将链接小提琴中的代码块添加到您的问题中,请确保从现在开始也这样做。
标签: jquery html scroll jquery-animate