35 lines
831 B
JavaScript
35 lines
831 B
JavaScript
|
(function () {
|
||
|
const pictures = [
|
||
|
'1',
|
||
|
'2',
|
||
|
'3',
|
||
|
'4',
|
||
|
'5',
|
||
|
'6',
|
||
|
'7'
|
||
|
];
|
||
|
|
||
|
const buttons = document.querySelectorAll('.btn');
|
||
|
const imgDiv = document.querySelector('.img');
|
||
|
|
||
|
let counter = 0
|
||
|
|
||
|
buttons.forEach(function (button) {
|
||
|
button.addEventListener("click", function (e) {
|
||
|
if (button.classList.contains('btn-left')){
|
||
|
counter--
|
||
|
if (counter < 0){
|
||
|
counter = pictures.length - 1
|
||
|
}
|
||
|
imgDiv.style.backgroundImage = `url('./img/${pictures[counter]}.jpg')`
|
||
|
}
|
||
|
if (button.classList.contains('btn-right')){
|
||
|
counter--
|
||
|
if (counter < 0){
|
||
|
counter = pictures.length - 1
|
||
|
}
|
||
|
imgDiv.style.backgroundImage = `url('./img/${pictures[counter]}.jpg')`
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
}) ();
|