【发布时间】:2014-04-23 20:44:03
【问题描述】:
我有一个脚本在 chrome 中运行良好,但在 Firefox 中运行良好,我不知道为什么会这样。该脚本假设从锚点向下滚动到一个 id,但在 Firefox 中什么也不做。
示例我如何使用下面的脚本!
<nav>
<ul>
<li><a class="scroll" target="home">Home</a></li>
</ul>
</nav>
<div id="home">
.....
</div>
<script>
$('.scroll').click(function() {
$(document).animate({
scrollTop: eval($('#' + $(this).attr('target')).offset().top - 70)
}, 1000);
});
</script>
【问题讨论】:
-
萤火虫有错误吗?
-
那个 eval 到底是干什么用的?
-
顺便说一句,您的
eval声明完全没有必要。 -
当我使用
$(document).animate时,我在 Chrome 中得到了Uncaught TypeError: Cannot use 'in' operator to search for 'display' in undefined的代码 - @Blazemonger 是完全正确的。
标签: javascript jquery html google-chrome firefox