【发布时间】:2015-02-14 13:40:59
【问题描述】:
如何在平滑滚动之前添加 3 秒的暂停? 用户点击按钮,然后休眠 3 秒,然后平滑滚动运行。
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
【问题讨论】:
-
请在您的帖子中使用代码块,而不是引用块作为示例代码。谢谢
-
@IsabelHM 已编辑,谢谢!
-
setTimeout(function() { ...your animate code here... }, 3000); -
@LawrenceCherone 非常感谢!
标签: javascript jquery scroll smooth-scrolling