If these banners are coming via database, in the Mysql for example there is the function ORDER BY RAND()
, where for each request he would bring a random item.
If you are just viewing images from a folder, you could list the images in a array
in the Javascript, and create a variable that generates a random value according to the amount of images, and that value would pull the specific item, for example:
var imagens = ["Imagem 1", "Imagem 2", "Imagem 3"]
var j = Math.floor((Math.random() * items.length) + 1);
Then you would call the image as follows:
imagens[j - 1]
I put -1 because J would generate values between 1 and the number of items, but the keys to array
are 0 the amount of itens-1
.
This way, whenever the page is reloaded the script will be re-executed, with this, it will always display a different image (or not, it is random, so it is possible to repeat twice or more the same image).
@gypsy-Morrison-Mendez can give me a light?
– Steve Angello