NTM NTM - 1 year ago 97
HTML Question

Slideshow transition - Javascript

I'm trying to do a slideshow gallery in Javascript, but it doesn't work... When I run this code, the

goes to
instantly, skipping the

<!DOCTYPE html>
<img id="img" src="ferrari.jpg" />
img = document.getElementById("img");
images = new Array("ferrari.jpg","lamborghini.jpg","veyron.jpg");
end = images.length -1;

window.onload = setInterval(slide,1000);
function slide(){
img.src = images[i];

Answer Source

why loop is exist here, you are casting all the images in all.

Do it with increment variable with start

            var img = document.getElementById("img");
            var images = new Array("ferrari.jpg","lamborghini.jpg","veyron.jpg");
            var end = images.length -1;
            var start = 0;
            window.onload = setInterval(slide,1000);        
            function slide(){
               img.src = images[start%end];

example fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download