2012-12-21 13 views
1

我想建立一個腳本,將阻止立即更改頁面,並首先運行動畫的鏈接。 這是我到目前爲止有:運行動畫,然後改變頁面 - jQuery的

$('a').click(function(event){ 
    event.preventDefault(); 

    $('#nav-bar').animate({ 
     left:'-260' 
    }, 1500, function(){ 
//want to use callback function to load the page.... 
      $(this).attr('href') what next? 

     } 
    ); 

我想重建在回調函數的默認事件和火災。是否有捷徑可尋? THanks

回答

3

設置window.locationhref

$('a').click(function(event){ 
    event.preventDefault(); 
    var href = this.href; 

    $('#nav-bar').animate({ 
     left:'-260' 
    }, 1500, function(){ 
     //want to use callback function to load the page.... 
     window.location = href; 
    } 
); 
3

使用window.location.href也可以導航所需的頁面,您還必須保存對單擊鏈接的引用,以便您可以在動畫回調中使用它。

$('a').click(function(event){ 
    event.preventDefault(); 
    var self = this; 
    $('#nav-bar').animate({ 
     left:'-260' 
    }, 1500, function(){ 
      window.location.href = self.href; 
     } 
    );