My goal is to design a carousel with images and have it horizontally scroll when the user hovers over the left or right side of the div. I've created two "invisible" divs for the controls on the left and right, each equipped with eventListeners:
right.addEventListener("mouseover", goRight)
function goRight() {
document.getElementById('images').scrollLeft += 20;
}
left.addEventListener("mouseover", goLeft)
function goLeft() {
document.getElementById('images').scrollLeft -= 20;
}
Currently, when I hover over the controls, the scrolling happens just once. To achieve continuous scrolling until mouseout, how can I make goRight()/goLeft() loop while hovering over the controls?