Skip to content

Commit

Permalink
Add keyboard navigation to image gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
mukeshtestgit committed Jun 17, 2024
1 parent 165c46a commit f435f31
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions Image-Gallery/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,36 @@ const nextE1 = document.getElementById("next");

let x = 0;
let timer;
prevE1.addEventListener("click", () => {

function onPrevButtonClick() {
x = x + 45;
clearTimeout(timer);
updateGallery();
});
nextE1.addEventListener("click", () => {
}

function onNextButtonClick() {
x = x - 45;
clearTimeout(timer);
updateGallery();
});
}

prevE1.addEventListener("click", onPrevButtonClick);
nextE1.addEventListener("click", onNextButtonClick);

function handleKeyDown(event) {
switch(event.key) {
case 'ArrowLeft':
// Simulate a click on the Prev button
onPrevButtonClick();
break;
case 'ArrowRight':
// Simulate a click on the Next button
onNextButtonClick();
break;
}
}

document.addEventListener('keydown', handleKeyDown);

function updateGallery() {
imageContainerE1.style.transform = `perspective(1000px) rotateY(${x}deg)`;
Expand All @@ -26,4 +46,3 @@ function updateGallery() {
}

updateGallery();

0 comments on commit f435f31

Please sign in to comment.