Created
April 25, 2021 09:59
-
-
Save walidum/690dd6700f184bf2ab04b92c82d7080c to your computer and use it in GitHub Desktop.
Slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var images = [ | |
'im01.jpg', | |
'im02.jpg', | |
'im03.jpg', | |
'im04.jpg', | |
'im05.jpg', | |
] | |
var cpt = 0 | |
function change() { | |
var img = document | |
.getElementById('img-slider') | |
img.setAttribute('src', 'images/' + images[cpt]) | |
} | |
setInterval(() => { | |
change(); | |
cpt++; | |
if (cpt > 4) cpt = 0; | |
}, 4000) | |
function next() { | |
cpt++; | |
if (cpt > 4) cpt = 0; | |
change() | |
} | |
function previous() { | |
cpt--; | |
if (cpt < 0) cpt = 4; | |
change() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment