2014-09-01 54 views
2

好吧,我有下面的代碼把不透明度DIV DIV後,函數運行後它需要500毫秒再次運行,我需要它來運行函數100毫秒或更少,在以前的動畫。運行回調函數

這裏是我的jQuery代碼:

var children = []; 
     $("#prod-general").children().each(function() { 
      children.push(this); 
     }); 

     function fadeThemOut(children) { 
      if (children.length > 0) { 
       var currentChild = children.shift(); 
       $(currentChild).set.animate({ 
        'opacity': '1'}, 
        500, function() { 
         fadeThemOut(children); 
       }); 
      } 
     } 

這裏是一個小提琴:http://jsfiddle.net/r5bqatpz/2/

+0

爲什麼不把100而不是500 – 2014-09-01 18:24:26

+0

@EhsanSajjad因爲動畫的速度會非常快,它需要是緩慢的,但該功能的執行時間應較小... – 2014-09-01 18:28:03

回答

2

使用超時:

var children = []; 
    $("#prod-general").children().each(function() { 
     children.push(this); 
    }); 

    function fadeThemOut(children) { 
     if (children.length > 0) { 
      var currentChild = children.shift(); 
      $(currentChild).set.animate({ 
       'opacity': '1'}, 
       500, function() { 
        //fadeThemOut(children); 
      }); 
      setTimeout(function() { 
       fadeThemOut(children); 
      },100); 
     } 
    } 

這裏是一個小提琴: http://jsfiddle.net/r5bqatpz/3/

+0

就是這樣!解決了我的問題。非常感謝! – 2014-09-01 18:29:55

+0

不用擔心。如果有幫助,請接受答案。 – 2014-09-01 18:31:30

+0

@JanHommes只需要等待15分鐘,OP就可以做到。 – 2014-09-01 18:34:05

1

正確解;這種替換你的方法: -

function fadeThemOut(children) { 
    if (children.length > 0) { 
     var currentChild = children.shift(); 
     $(currentChild).animate({ 
       'opacity': '1' 
      }, 
      500); 
     var myVar = setInterval(function() { 
      fadeThemOut(children); 
     }, 100); 

    } 
}