animation - jquery animate image stop -


how can let animation stop @ last image , let stand on last image? maybe can me stop animation.

var myimages = [     "http://placekitten.com/200/200",     "http://placekitten.com/150/150",     "http://placekitten.com/180/180",     "http://placekitten.com/170/170",     "http://placekitten.com/140/150",     "http://placekitten.com/160/160" ]; var counter = 1;  // start @ number 2 since html tag has first  function switchimage() {     $('#myimage').attr('src', myimages[counter]);     counter += 1;      if (counter == myimages.length) {         counter = 0;     } }  $(document).ready(function() {     setinterval(switchimage, 5000); }); 

setinterval() returns interval id, can pass clearinterval().

var refreshintervalid; var myimages = [     "http://placekitten.com/200/200",     "http://placekitten.com/150/150",     "http://placekitten.com/180/180",     "http://placekitten.com/170/170",     "http://placekitten.com/140/150",     "http://placekitten.com/160/160" ]; var counter = 1;  // start @ number 2 since html tag has first  function switchimage() {     $('#myimage').attr('src', myimages[counter]);     counter += 1;      if (counter == myimages.length) {         counter = 0;         clearinterval(refreshintervalid);     } }  $(document).ready(function() {    refreshintervalid = setinterval(switchimage, 5000); }); 

demo fiddle


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

html - Repeat image to extend header to fill screen -

javascript - Backbone.js getting target attribute -