307 current 2025-02-02 19:29:41 25.05.20241217.d3c42f1 6.6.66 *
This commit is contained in:
41
home/programs/firefox/startpage/scripts/visuals.js
Normal file
41
home/programs/firefox/startpage/scripts/visuals.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const img = document.getElementById('mainImg');
|
||||
const btnImg = document.getElementById('image-cycle');
|
||||
const btnImg_bw = document.getElementById('image-cycle-bw');
|
||||
|
||||
/**
|
||||
* Images to be used
|
||||
*/
|
||||
|
||||
const images = [];
|
||||
for (let i = 1; i <= 28; i++) {
|
||||
images.push(`t${i}.jpg`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index of the image. Revert the the first image if nothing found
|
||||
* in the local storage.
|
||||
*/
|
||||
let imgIndex = localStorage.getItem('imgIndex') || 0
|
||||
|
||||
/*
|
||||
* Load image on page load.
|
||||
*/
|
||||
img.src = 'assets/img/' + images[imgIndex]
|
||||
|
||||
/**
|
||||
* Change image when clicking the button.
|
||||
*/
|
||||
function changeImg() {
|
||||
imgIndex = (imgIndex + 1) % images.length
|
||||
img.src = 'assets/img/' + images[imgIndex]
|
||||
localStorage.setItem('imgIndex', imgIndex)
|
||||
}
|
||||
|
||||
function changeImg_bw() {
|
||||
imgIndex = (imgIndex + images.length - 1) % images.length
|
||||
img.src = 'assets/img/' + images[imgIndex]
|
||||
localStorage.setItem('imgIndex', imgIndex)
|
||||
}
|
||||
|
||||
btnImg.addEventListener('click', changeImg)
|
||||
btnImg_bw.addEventListener('click', changeImg_bw)
|
||||
Reference in New Issue
Block a user