2012-03-31 40 views
0

我使用這個jQuery腳本淡出並在頁面褪色,jQuery的淡出和淡入不會重定向我

<script type="text/javascript"> 
$(document).ready(function() { 
    $("body").css("display", "none"); 
    $("body").fadeIn(1000); 

    $("li").click(function(event){ 
     event.preventDefault(); 
     linkLocation = this.href; 
     $("body").fadeOut(1000, redirectPage); 
    }); 

    function redirectPage() { 
     window.location = linkLocation; 
    } 
}); 
</script> 

淡出部分運作良好,但是,淡入,犯規。確切地說,頁面淡出,然後過渡到第二頁面,但它不會重定向到鏈接位置,而是「未定義」。

導航是在其中產生

<ul> list with <li>. 

任何建議PHP? :)

回答

0

linkLocation僅在$(document).ready()匿名函數內定義,因此您的redirectPage()函數不知道linkLocation的值是多少。你必須使用它,像這樣:

$("body").fadeOut(1000, function() { 
    window.location = linkLocation; 
}); 
0

li元素其實有href屬性?

確定href屬性不屬於<a>元素,並且您引用了錯誤的元素this

<li id="mylist" href="http://google.com"></li> 

對我來說很陌生?

+0

耶!我用「a」替換了li,它起作用了,歡呼 – 2012-03-31 01:32:41

+0

@PeterAbsolon - 如果答案是正確的,你應該接受它? – adeneo 2012-03-31 01:41:18