35 lines
990 B
JavaScript
Raw Normal View History

2023-01-21 23:57:03 +01:00
$(function () {
var index = 0
const maxIndex = 5
const delay = 7000
function showImage(idx) {
2023-01-21 23:57:23 +01:00
// console.log("switching to index", idx)
const imgs = $('#header .slider .slider-img')
2023-01-21 23:57:03 +01:00
imgs.eq(idx).removeClass('hidden')
imgs.filter((i, e) => {return i != idx}).addClass('hidden')
2023-01-21 23:57:23 +01:00
const dots = $('#header .slider .dots .dot')
dots.removeClass('active')
dots.eq(idx).addClass('active')
index = idx
2023-01-21 23:57:03 +01:00
}
function getNextIndex() {
const ret = index + 1
if (ret > maxIndex) {
return 0
} else {
return ret
}
}
function nextImage() {
const newIdx = getNextIndex()
showImage(newIdx)
setTimeout(nextImage, delay)
}
// setTimeout(nextImage, delay)
2023-01-21 23:57:23 +01:00
$('#header .slider .dots .dot').click(function (evt) {
// console.log(evt)
const newIdx = $(evt.target).data('index')
showImage(newIdx)
})
2023-01-21 23:57:03 +01:00
})