2
我正在尝试为我的网站制作幻灯片动画。核心功能在那里,但我遇到了问题,只要我点击一个元素(当页面不是顶部)页面跳转到顶部和顶部,然后按照预期制作动画。我研究了最后几天,但我的问题似乎是独一无二的,所以我决定提出这个问题。这是我的本钱:jQuery页面在执行动画之前跳转到顶部
<div class="content">
<div class="inner_content">
<div id="first" class="first"></div>
<div id="second" class="second"></div>
<div id="third" class="third"></div>
</div>
</div>
的想法是点击一个DIV(第一,第二,第三),从顶部因为导航栏的130像素的偏移滚动起来。这是我的jQuery:
<script>
$("div.first").click(function(){
$("html, body").animate({
"scrollTop": $("div.first").offset().top -130
}, 500);
$("div.second").click(function(){
$("html, body").animate({
"scrollTop": $("div.first").offset().top -130
}, 500);
$("div.third").click(function(){
$("html, body").animate({
"scrollTop": $("div.first").offset().top -130
}, 500);
</script>
问题就在于说。页面会非常快速地跳到页面顶部,然后返回到上一个位置。之后,滑动上下动画非常干净平滑。我真的不知道问题出在哪里。我希望有人能帮助我。 在此先感谢。
它看起来像你的括号/括号缺少一些在end –
这对自己的工作很好http://jsfiddle.net/99W3P/1/在你的实际代码中必须有其他东西。你碰巧有''''只有'#''href'吗? http://jsfiddle.net/99W3P/2/ –
@JamesMontagne'你碰巧有一个的href只是#?'。 这就是确切点。非常感谢。我在两天前发现了自己,但无法访问互联网将其标记为已解决。不管怎么说,多谢拉。 – chris115379