Created
May 16, 2020 09:26
-
-
Save mcsolha/d47928203a861f6ddea87676ccf5f8ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onHold(el, cb) { | |
let interval; | |
el.addEventListener('mousedown', () => interval = setInterval(() => requestAnimationFrame(cb), 10)); | |
el.addEventListener('mouseup', () => clearInterval(interval)); | |
el.addEventListener('mouseleave', () => clearInterval(interval)); | |
} | |
function slider({ | |
target, | |
rightButton, | |
leftButton, | |
}) { | |
function scrollToRight() { | |
container.scrollLeft += 10; | |
} | |
function scrollToLeft() { | |
container.scrollLeft -= 10; | |
} | |
onHold(buttonRight, scrollToRight); | |
onHold(buttonLeft, scrollToLeft); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment