【发布时间】:2012-08-02 15:59:18
【问题描述】:
下午
问题:我的“返回顶部”按钮(向下滚动后的右下角)不是通过动画滚动到顶部,而是直接跳到顶部。
例子可以在http://www.pixsters.be找到
我的html:
<a href="#top" id="homebacktothetop"><span>backtothetop</span></a>
我的 js (jquery):
// scroll to 0 when clicked
$('#homebacktothetop').click(function () {
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
});
【问题讨论】:
-
不知道。但是点击事件处理程序有一个
preventDefault方法,如果你想阻止链接正常工作,你可以使用而不是return false;。.click(function(e){ e.preventDefault(); });
标签: javascript jquery scroll