【发布时间】:2015-12-16 15:11:35
【问题描述】:
我有一个基本脚本,当用户单击它们时,它会平滑滚动到锚定链接。我的问题是平滑滚动似乎只能以一种方式工作,当我单击“转到顶部”链接之一时,页面只是跳转......
$(function(){
// Smooth scrolling for anchored links
$('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
}, 2000);
return false;
}
}
});
// Scroll down automatically on page load
$('html, body').animate({
scrollTop: $('.destination').offset().top
}, 2000);
});
https://jsfiddle.net/p70d4doq/22/
任何帮助将不胜感激!
谢谢,安德烈亚斯
【问题讨论】:
-
我觉得不错。
:)
标签: javascript jquery hyperlink anchor smooth-scrolling