0
How do i make array that will shuttle and display different a image and content in every reload.- JavaScript
An array that shows a different image and content in every reload on javascript.
7 Answers
+ 1
You mean you want your page to display a random image everytime the page is loaded in browser?
+ 1
Are you into doing this on the back-end also, or just on the front-end? I had to ask, cause there will be differences in either way to approach this.
If you're only changing an image then use of array will do. But if you're into displaying different content also, well that's where you probably wanna look into back-end stuffs. Cause that sounds like a work of a CMS to me ...
+ 1
Favour Chidera Please at least structure your code a bit to make it readable.
https://code.sololearn.com/WHHtgsIYTm42/?ref=app
0
Yea ..i kind of blog style whereby: once you reload the page, a different blog image and its content apears
0
Hard to tell what's your intension without looking at a code.
Try using:
window.addEventListener("load", () => {
imageSrc = yourImageArray[Math.Floor(Math.Random*yourImageArray.lengh)];
})
0
Create an array to store your images, then call the "DOMcontentLoaded" event listener and pass in a function Math.Random() to load a different image upon page reload from your array