menu

Questions & Answers

jquery code that makes automatic picture change to next

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.

Comments:
2023-01-23 00:20:08
Without any code, we can't help much, only guess. Please see this article: How to create a minimal reproducible example.
2023-01-23 00:20:08
You seem to describe a carousel, you could look for "jquery carousel"
Answers(2) :

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.

Comments:
2023-01-23 00:20:08
I will look in that, thanks for more information on this topic!

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

Comments:
2023-01-23 00:20:08
nope, doesn`t work
2023-01-23 00:20:08
share the code you have written
2023-01-23 00:20:08
where are you storing your image
2023-01-23 00:20:08
and what error are you getting with the above code, I might help it out
2023-01-23 00:20:08
I got an error because of this character , but other comment reminded me that bootstrap exists because I forgot about that lol.
2023-01-23 00:20:08
ok, you can upvote my answer if you want, thanks anyway