使用 waypoint.js 处理一个函数,该函数获取视口(viewport)中的当前 div,并在单击按钮时找到下一个 div。
目前我得到一个未定义的“下一个”值。不确定哪里出了问题,我猜这个值不能从航路点函数移动到点击函数。任何帮助都会很可爱。
$('.wrap').waypoint(function() {
var next = $(this).next();
$(".button").click(function() {
$("html, body").animate({ scrollTop: next.offset().top }, 1000);
});
});
最佳答案
我建议你链接它而不是在回调中这样做:
$('.wrap').waypoint().addBack(this).find(".button").click(function() {
var next = $(this).closest('.wrap').next();
$("html, body").animate({ scrollTop: next.offset().top }, 1000);
});
或者可能是这样的:
$('.wrap').waypoint().done(function(){
$(this).find(".button").click(function() {
var next = $(this).closest('.wrap').next();
$("html, body").animate({ scrollTop: next.offset().top }, 1000);
});
});
关于javascript - 航点js点击到下一个div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27544080/