add time on each object initialization

I'm initializing a jQuery notification plugin using the following code. I used setTimeout function to delay each object init.

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)
    })
}

The problem is all the objects get's shown in after the delay time period. There is no time difference in each object. how can I achieve the time difference on each object.

I use the following plugin : http://hakanersu.github.io/AmaranJS/

Answers


The problem in your code is all the elements in the array is using a constant delay of 1000 ms, since you want to display one by one, you can use a dynamic delay 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)
    })
}

Need Your Help

How to use a code igniter class in Wordpress?

php wordpress codeigniter

The class I wish to use is: https://github.com/philsturgeon/codeigniter-curl/blob/master/libraries/Curl.php

Table Stats gathering for Oracle

oracle table-statistics

When and how should table stats gathering be performed for Oracle, version 9 and up? How would you go about gathering stats for a large database, where stats gathering would collide with "business

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.