您好我已经写了一些代码,滚动页面后,点击一个元素,但在平滑滚动之前,跳转到页面的顶部。有人能解释我做错了什么吗?jQuery - 平滑滚动到div
这是脚本
$('a[href*="#"]').click(function(e){
e.preventDefault();
if($(this).attr('href') == '#') {
$('html, body').animate({
scrollTop: $('body').offset().top
}, 1000);
window.location.hash = '';
} else {
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top - $(this).height()
}, 1000);
window.location.hash = $(this).attr('href');
}
return false;
});
,并告诉我,我在哪里可以学习JS :)请
Go thro'以下链接为学习和Masterin g JS :) http://stackoverflow.com/questions/2687566/learning-javascript-in-one-weekend http://stackoverflow.com/questions/11246/best-resources-to-learn-javascript –
将此行放入'window.location.hash ='''是什么原因?你有没有尝试没有这条线? – anu
是的,我已经尝试了很多配置,但它仍然“跳跃”在Firefox中 – arclite