簡單分享

關於工作, 3C, IT觀點, web design, graphic design........ 厭倦了花俏的頁面, 真正的eye-Candy是安靜不起眼的襯托! less is more...... 
« Back to blog

jQuery delay

利用jQuery delay來控制UI的流程是非常優雅的實作方式
1. 先引入James Padolsey寫的delay function

$.fn.delay = function(time, callback){
     // Empty function:
     jQuery.fx.step.delay = function(){};
     // Return meaningless animation, (will be added to queue)
     return this.animate({delay:1}, time, callback);
}

2.用selector挑取要做delay的元素, 如

$('#querystatus').show().delay(3000, function(){
     ......
     $('#querystatus').hide().delay(500,function(){
         ......
         ......
     });
});

呈現的結果將會是:
查詢狀態(querystatus)顯示3秒後, 讓自己消失, 並在消失0.5秒後, 執行指定的code

Loading mentions Retweet
Posted by Jerry 

Comments (0)

Leave a comment...

 
Got an account with one of these? Login here, or just enter your comment below.
Posterous-login    Connect    twitter