亲爱的stackoverflowers,
我有两个似乎不能一起正常工作的 javascript 片段。第一个是在导航中的单击事件上淡出正文,然后重定向到不同的页面。但这似乎只有在我单击触发“JavaScript-2”的链接后才有效。
这是第一个的代码:
// JavaScript-1
<script type="text/javascript">
$("a.transition").click(function(event){
event.preventDefault();
linkLocation = this.href;
$("body").fadeOut(1000, redirectPage);
});
function redirectPage() {
window.location = linkLocation;
}
</script>
'JavaScript-2' 是第二个,它与 'jquery.easing.1.3.js' 一起工作,并产生很好的平滑滚动到锚点。滚动总是可以正常工作,并且在所有情况下都会触发。
我不知道为什么,但看起来平滑滚动的 javascript 会导致其他 javascript 失败。
我真的很期待这个小谜团的答案。
这是第二个的代码:
// JavaScript-2
<script type="text/javascript">
$(function() {
$('ul.navscroll a, #test a').bind('click',function(event){
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500,'easeInOutExpo');
event.preventDefault();
});
});
</script>