jquery - How do I changes this code to make images rotate on refresh? -
I have recently asked how to rotate the images on an element and presented with this code - Which works perfectly:
counter = 1; Num_images = 9; Dir = "Image Director URL"; Function rotate image () {var background_img = 'url (' + dir + '/ image' + counter + '. Gif)'; JQuery ('# fader.category'). Fade (function () {jQuery ('# fader.category'). CSS ('background-image', background_image). FadeIn ('slow');}); Counter ++; If (counter> number_image) counter = 1; } Set intern ("rotate image ()", 25000);
My question is now: How can I customize this code to change images when I refresh a page? I am new to jQuery and Javascript in general so if someone provides a solution, please tell how this works, so I can learn and hopefully ask fewer questions later ... Thanks a lot. .
I use a random initial image to give you the illusion of change on every page load / refresh I recommend to do Otherwise you are left with writing a cookie of the last seen image and showing the next one on the page load:
Change the following two lines as follows (notice I reverse their purpose ):
number_imaj = 9; // Choose a random initial number counter = mathematics. Syll (mathematics.rendum) * num_images);
Of course there is a possibility of the same image that is randomly appearing again in a row, but it will probably be very close to your will.
Comments
Post a Comment