Skip to content

Instantly share code, notes, and snippets.

@walidum
Created April 25, 2021 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walidum/690dd6700f184bf2ab04b92c82d7080c to your computer and use it in GitHub Desktop.
Save walidum/690dd6700f184bf2ab04b92c82d7080c to your computer and use it in GitHub Desktop.
Slider
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