Mayank
Mayank

Reputation: 165

Run instagram code after specific interval of time

I want to display the pictures from my Instagram to website. I am successful with the image display part, but when new Images are uploaded with the Tag i have mentioned then I want to display it at without refreshing the browser. I want to just call the code again and again after 1 sec.

var feed = new Instafeed({
  clientId: 'fd49a37da9f04a47b046395a5d2a8fb9',
  limit: 17 ,
  get:'tagged',
  tagName:'kdy14',
  after: function () {
    var images = $("#instafeed").find('a');
    $.each(images, function(index, image) {
      var delay = (index * 75) + 'ms';
      $(image).css('-webkit-animation-delay', delay);
      $(image).css('-moz-animation-delay', delay);
      $(image).css('-ms-animation-delay', delay);
      $(image).css('-o-animation-delay', delay);
      $(image).css('animation-delay', delay);
      $(image).addClass('animated flipInX');
    });
  },
  template: '<a href="{{link}}" target="_blank"><img src="{{image}}" /></a>'
});
feed.run();

I want to make this JS run after every 1 sec. How can I so this.

Upvotes: 0

Views: 170

Answers (2)

Andy
Andy

Reputation: 63524

The alternative to setInterval is a recursive setTimeout function which some people seem to prefer:

var timer;
(function looper() {
  feed.run();
  timer = setTimeout(looper, 1000);
}());

And to clear it:

clearTimeout(timer);

DEMO

Upvotes: 0

Youness
Youness

Reputation: 1495

use :

setInterval(function(){feed.run();}, 1000);//1000 is 1 s

PS : if you want to stop it in some place do this :

//first put the interval ID in an a var
   var intervalID = setInterval(function(){feed.run();}, 1000);

//then when you want to stop it just do 
    clearInterval(intervalID);

Upvotes: 1

Related Questions