2013-08-30 35 views
2

我該怎麼做,當我點擊一個按鈕,它會首先.fadeIn(0); .dealy(2000); .fadeOut(600); and say "Validating..."那麼它會說"Success fully log in"並重定向到index.php?如何有兩個時尚,延遲和淡出另一個?

我沒有嘗試這一點,但沒有奏效:

function save() { 
    $('#save_first').html('Validating...'); 
    $('#save_first').fadeIn(1); 
    $('#save_first').delay(2000); 
    $('#save_first').fadeOut(600); 
    $('#save_second').html('Success fully log in!'); 
    $('#save_second').delay(2601); 
} 

HTML

header('Location: index.php'); 
     exit(); 
+1

你可以分享一些HTML的任何方式,使我能迅速的小提琴? – brbcoding

回答

5

堆疊起來並用的setTimeout一起使用,其餘的回調對重定向

var loginUser = function(){ 

    $('#save_first').fadeIn(1).delay(2000).fadeOut(600, function(){ 
     $('#save_second').html('Success fully log in!'); 
     //Redirect after 2.6 seconds delay 
     setTimeout(function() { 
      window.location.href = "/index.php"; 
     }, 2600); 
    }); 

}; 

然後只要你想觸發就行:

loginUser(); 

觸發的「元素」的點擊信息:

$(element).click(loginUser); 
+0

oki但是如何在完成後將它們重定向到一側? @charlitosJS – user2733334

+0

只需使用setTimeout函數重定向即可。我用它更新了代碼。 – charlitosJS

+0

oki謝謝你! :) – user2733334