2010-02-25 53 views
1

给出下面的代码的任何想法为什么突出显示被触发两次运行?我确认它使用两次以上的警报运行两次。在这里看到什么不对?JQUERY在此ScrollTo Highlight代码段中运行两次?

//Scroll to the Anchor in the URL, if there is one 
var destination = $(document.location.hash).offset().top; 
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500, function() { 
// Animation complete. 
$(document.location.hash).effect("highlight", {}, 3000); 
}); 

回答

2

在Firebug控制台中运行您的选择器。我很确定它会返回两个项目。在控制台中运行“$(”html:not(:animated),body:not(:animated)“)。size()”,你会明白我的意思。在几乎任何网页上,你都会得到一个匹配的html:not(:animated)以及body:not(:animated)。选择器中的逗号表示“选择所有指定选择器的组合结果”。 API Document is here。而对animate的调用将作用于返回的包装集合中的每个元素。也许别的事情正在发生,但我会先检查包裹的大小。