2013-05-08 62 views
0

我想在兩個函數之間添加wait()或延遲。在兩個條件之間添加延遲

function(imageID) 
    { 
     //alert("i main slider called "); 

     if(en==1) 
     { 
      var selected=$('#' + sel); 
      $(selected).animate({"left": "+=30px","opacity": "0.99"},"slow"); 
      $(selected).animate({"height":"354px","width":"295px"},30); 
      $(selected).css("-webkit-transform-style","preserve-3d"); 
      $(selected).css("-webkit-transition","all 1.0s linear"); 
      $(selected).css("transform-style","preserve-3d"); 
      $(selected).css("transition","all 1.0s linear"); 
      $(selected).css("-webkit-transform","rotateY(0deg)"); 
      $(selected).css("transform","rotateY(0deg)"); 
      en=0; 
     } 

     if(my.circular) 
     { 
      /* Trigger left jumppoint */ 
      if(imageID+1 === my.imageFocusMax) 
      { 
       /* Set jump target to the same cloned image on the right */ 
       clonedImageID = my.max - my.imageFocusMax; 
       jumpTarget = -clonedImageID * my.xStep; 

       /* Set the imageID to the last image */ 
       imageID = clonedImageID-1 ; 
      } 

在我的函數中,我想在if語句之後添加一個delar。我怎樣才能做到這一點?我曾嘗試添加delay(),但它不起作用。我應該使用什麼?

+0

使用'的setTimeout()' – Santosh 2013-05-08 12:55:14

+0

看看這個鏈接http://stackoverflow.com/questions/1183872/put-a-delay-in-javascript – Santosh 2013-05-08 12:55:42

+0

下面是解 http://stackoverflow.com/問題/ 4437600/sleep-in-jquery – 2013-05-08 12:56:11

回答

3

使用setTimeout函數。這樣你可以告訴瀏覽器在做某事之前等待。