Added dots to slider

This commit is contained in:
2023-01-21 23:57:23 +01:00
parent 0ec4b0eb68
commit 5cc05de0dc
3 changed files with 44 additions and 2 deletions

View File

@@ -3,9 +3,14 @@ $(function () {
const maxIndex = 5
const delay = 7000
function showImage(idx) {
// console.log("switching to index", idx)
const imgs = $('#header .slider img')
imgs.eq(idx).removeClass('hidden')
imgs.filter((i, e) => {return i != idx}).addClass('hidden')
const dots = $('#header .slider .dots .dot')
dots.removeClass('active')
dots.eq(idx).addClass('active')
index = idx
}
function getNextIndex() {
const ret = index + 1
@@ -17,10 +22,13 @@ $(function () {
}
function nextImage() {
const newIdx = getNextIndex()
console.log("switching to index", newIdx)
showImage(newIdx)
index = newIdx
setTimeout(nextImage, delay)
}
setTimeout(nextImage, delay)
$('#header .slider .dots .dot').click(function (evt) {
// console.log(evt)
const newIdx = $(evt.target).data('index')
showImage(newIdx)
})
})