我正在写一个测验网页ap的开头标题,然后是10个问题。开头的div和每个问题的div都是兄弟,所以我通过将current.nextSibling和current.previousSibling传递给我正在使用的任何函数来遍历页面。jQuery的scrollTop麻烦
现在我试图通过jQuery的'animate'和'scrollTop'方法创建一个平滑的滚动,但它不工作。有没有人有这个想法?这里附带的代码,链接捣鼓这里:https://jsfiddle.net/fjydnc9m/1/
var main = function() {
var root = $('html, body');
var current = document.getElementById("opening");
$('.upButton').click(function() {
$('html, body').animate({ scrollTop:$(current.previousSibling).offset().top}, 2000);
current = current.previousSibling;
});
$('.downButton').click(function() {
$('html, body').animate({ scrollTop: $(current.nextSibling).offset().top}, 2000);
current = current.nextSibling;
});
}
$(document).ready(main);
当我说它不工作我的意思是什么都没有发生,当我点击我的向下按钮,类“.downButton”,并与其他按钮分类相同“.upButton” –
请把真实的代码,而不是一个图像。这将确保为每个人提供更好的可读性。 –
甚至更好,请提供一个jsfiddle! – Connum