As a newbie to JavaScript,
I have a question regarding multiple keypress events and how to assign them to different actions.
Here is the code snippet:
var imga = ["http://img1.jpegbay.com/gallery/004236128/1_t.jpg",
"http://img1.jpegbay.com/gallery/004236128/2_t.jpg",
"http://img1.jpegbay.com/gallery/004236128/3_t.jpg",
"http://img1.jpegbay.com/gallery/004236128/4_t.jpg",
"http://img1.jpegbay.com/gallery/004236128/5_t.jpg",
"http://img1.jpegbay.com/gallery/004236128/6_t.jpg",
"http://img1.jpegbay.com/gallery/004236128/7_t.jpg",
"http://img1.jpegbay.com/gallery/004236128/8_t.jpg",
];
var imgb = ["http://img1.jpegbay.com/gallery/004236316/1_t.jpg",
"http://img1.jpegbay.com/gallery/004236316/2_t.jpg",
"http://img1.jpegbay.com/gallery/004236316/3_t.jpg"
];
window.addEventListener("keydown", checkKeyPressed, false);
function checkKeyPressed(e) {
if (e.keyCode == "65") {
changeImage(-1);
}
if (e.keyCode == "66") {
changeImage(-1);
}
};
function changeImage(dir) {
var img = document.getElementById("imgClickAndChange");
img.src = imga[imga.indexOf(img.src)+dir] || imga[(dir==1) ? 0 : imga.length-1];
var img = document.getElementById("b");
img.src = imgb[imgb.indexOf(img.src)+dir] || imgb[(dir==1) ? 0 : imgb.length-1];
}
You can also access this on JSFiddle:
http://jsfiddle.net/k3wxhc58/39/
The setup involves two sets of images assigned to the A and B buttons, where pressing either button switches the displayed image.
I aim to extend this functionality to cover the entire alphabet.
Additionally, I am exploring if using THREE.js library for creating typographical animation with 3D models rendered from JSON would be a more efficient approach.
This project is my first dive into coding, so everything you see here is a result of my research and experimentation.
Appreciate your help!
J