Create basic slider

This commit is contained in:
2023-01-21 23:57:03 +01:00
parent 085096a8fe
commit 0ec4b0eb68
5 changed files with 41 additions and 3 deletions

View File

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

View File

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 140 KiB

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,26 @@
$(function () {
var index = 0
const maxIndex = 5
const delay = 7000
function showImage(idx) {
const imgs = $('#header .slider img')
imgs.eq(idx).removeClass('hidden')
imgs.filter((i, e) => {return i != idx}).addClass('hidden')
}
function getNextIndex() {
const ret = index + 1
if (ret > maxIndex) {
return 0
} else {
return ret
}
}
function nextImage() {
const newIdx = getNextIndex()
console.log("switching to index", newIdx)
showImage(newIdx)
index = newIdx
setTimeout(nextImage, delay)
}
setTimeout(nextImage, delay)
})