所以我只想从当前可见的类滚动到该类的下一个实例。
HTML看起来像这样
<div class="container">
<div class="section">
` <p> lorem ipsum </p>
<a href="javascript:void(null)" class="next"> next section </a>
</div>
<div>
^重复'x'次]
我的js:
$(.next).click(function(e){
$('html,body').animate({},
scrollTop: $(this).parent().next().offset().top
},'slow');
});
很显然,该代码无法正常工作,因为它只会带您进入下一个div,但我是新手,非常感谢您的帮助。
您需要使用.closest(".container")
才能到达父容器。然后使用.next()
删除动画方法开始时的},
。