Home > database >  jquery code that makes automatic picture change to next
jquery code that makes automatic picture change to next

Time:01-23

I don`t exactly know how to ask this but I will try, I want that image every 3 seconds changes to next image with jquery.

I didn`t found any information on this topic.

CodePudding user response:

well since there is no code posted i dont think there can be a answer that completely satisfies you.

But you can use setInterval(), in order to call the function that changes picture every 3 seconds.

I suggest you look up Image Slider on the internet for effects that you want.

you can also check Carousel, that you can use it with setInterval.

CodePudding user response:

I had done something like that some 2/3 years ago but I think I can recollect this from my memory, for this I stored the image in a local directory and declared an array something like below

const arr={ 'path1', 'path2', 'path3', 'path4'}

and then use setinterval for every 3 seconds

setInterval(function () {
   $('#imgTagId').attr('src', arr[i]);
   if(i>=arr.length)
       i=0
   else
       i 1
}, 3000);

this is how I used it, it might be wrong but worked for me

let me know if it worked

  • Related