How to make a slideshow using Javascript

Опубликовано: 08 Июнь 2026
на канале: Programminglessons
7,121
8

In this tutorial i will explain how to make a slideshow using Javascript.

Explanation of code:

document.getElementById is used to grab a html element with an id.
imageIndex is used to set the index of imageArray
imageIndex++ adds 1 to imageIndex everytime the function is runned.
setAttribute is used to set the src of the image eqaul to imageIndex
the if statement is used to bring imageIndex back to 0 everytime it exceeds the number of images.
setInterval sets the interval between the changing of images. First a function (or element)and then the interval in MILLISECONDS.

All music made by myself with Garageband