Created
January 5, 2018 17:19
-
-
Save TheServer201/e1c63e8e8797a874b5e7711fc15598c1 to your computer and use it in GitHub Desktop.
Scroll without a scrollbar
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
.scroll { | |
overflow: hidden; | |
cursor: move; | |
touch-action: none; | |
} |
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
window.onload = () => { | |
let element = document.getElementById('zone'), scroll = [false, 0, 0]; | |
element.onpointerdown = event => { | |
scroll[2] = event.clientY; | |
scroll[1] = event.clientX; | |
scroll[0] = true; | |
}; | |
element.onpointermove = event => { | |
if (scroll[0]) { | |
element.scrollLeft += scroll[1] - event.clientX; | |
element.scrollTop += scroll[2] - event.clientY; | |
} | |
}; | |
window.onpointerup = () => { | |
scroll[0] = false; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment