2015-01-19 2 views
0

다음 코드를 사용하여 jQuery 알림 플러그인을 초기화하고 있습니다. setTimeout 함수를 사용하여 각 객체를 지연 시켰습니다.각 객체 초기화에 시간을 추가하십시오.

if(applicablePromotions.length > 0){ 
    applicablePromotions.forEach(function(promo){ 
     setTimeout(function(){ 
      $.amaran({ 
       content:{ 
        title:'Your Download is Ready!', 
        message:'1.4 GB', 
        info:'my_birthday.mp4', 
        icon:'fa fa-download' 
       }, 
       theme:'awesome ok', 
       position:'top left', 
       inEffect:'slideRight', 
       outEffect:'slideLeft' 
      }); 
     },1000) 
    }) 
} 

지연 시간이 지나면 모든 객체가 표시됩니다. 각 개체에는 시차가 없습니다. 각 개체에 대해 어떻게 시간차를 얻을 수 있습니까?

나는 다음과 같은 플러그인을 사용 : http://hakanersu.github.io/AmaranJS/

답변

1

코드의 문제는 당신이 하나씩 표시 할부터 배열의 모든 요소가 동적 지연을 사용할 수 있습니다, 1000 ms의 일정 지연을 사용하고있다 like

if (applicablePromotions.length > 0) { 
    applicablePromotions.forEach(function (promo, i) { 
     setTimeout(function() { 
      $.amaran({ 
       content: { 
        title: 'Your Download is Ready!', 
        message: '1.4 GB', 
        info: 'my_birthday.mp4', 
        icon: 'fa fa-download' 
       }, 
       theme: 'awesome ok', 
       position: 'top left', 
       inEffect: 'slideRight', 
       outEffect: 'slideLeft' 
      }); 
      //use a dynamic delay 
     }, (i + 1) * 1000) 
    }) 
} 
관련 문제