I am trying to create a carousel of images and wanted to horizontal scroll when the user hovers over the left and right side of the div. I have two "invisible" divs for the left and right controls and gave them eventListeners:
right.addEventListener("mouseover", goRight)
function goRight() {
document.getElementById('images').scrollLeft += 20;
}
left.addEventListener("mouseover", goLeft)
function goLeft() {
document.getElementById('images').scrollLeft -= 20;
}
When I hover over them, it will scroll once, but I would like it to continuously scroll until I mouseout. How I can I make goRight()/goLeft() loop while I am hovering on the controls?