2023-01-21 22:57:03 +00:00
|
|
|
$(function () {
|
|
|
|
var index = 0
|
2024-11-16 14:57:43 +00:00
|
|
|
const maxIndex = numImages - 1
|
2024-01-07 15:53:53 +00:00
|
|
|
const delay = 6000
|
|
|
|
const shuffeledIndices = []
|
|
|
|
|
|
|
|
for(let i=0; i<=maxIndex; i++){
|
|
|
|
shuffeledIndices.push(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shuffle by Fisher-Yates algorithm
|
|
|
|
for(let i=maxIndex; i>= 0; i--) {
|
|
|
|
const j = Math.floor(Math.random() * (i+1))
|
|
|
|
const tmp = shuffeledIndices[j]
|
|
|
|
shuffeledIndices[j] = shuffeledIndices[i]
|
|
|
|
shuffeledIndices[i] = tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
function showImage(idxidx) {
|
|
|
|
const idx = shuffeledIndices[idxidx]
|
2023-01-21 23:02:29 +00:00
|
|
|
const imgs = $('#header .slider .slider-img')
|
2023-01-21 22:57:03 +00:00
|
|
|
imgs.eq(idx).removeClass('hidden')
|
|
|
|
imgs.filter((i, e) => {return i != idx}).addClass('hidden')
|
2023-01-21 22:57:23 +00:00
|
|
|
const dots = $('#header .slider .dots .dot')
|
|
|
|
dots.removeClass('active')
|
2024-01-07 15:53:53 +00:00
|
|
|
dots.eq(idxidx).addClass('active')
|
|
|
|
index = idxidx
|
2023-01-21 22:57:03 +00: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)
|
|
|
|
}
|
2024-01-07 15:53:53 +00:00
|
|
|
|
|
|
|
showImage(0)
|
|
|
|
|
|
|
|
// Start the animaions delayed to allow for showing the first image directly
|
|
|
|
setTimeout(() => {
|
|
|
|
$('#header .slider .slider-img').addClass('animated')
|
|
|
|
}, 150)
|
|
|
|
|
|
|
|
setTimeout(nextImage, delay)
|
2023-01-21 22:57:23 +00:00
|
|
|
$('#header .slider .dots .dot').click(function (evt) {
|
|
|
|
// console.log(evt)
|
|
|
|
const newIdx = $(evt.target).data('index')
|
|
|
|
showImage(newIdx)
|
|
|
|
})
|
2023-01-21 22:57:03 +00:00
|
|
|
})
|