Created
March 30, 2021 19:30
-
-
Save MikelArnaiz/fa8bc91565d83b49fbfe71f824f147f6 to your computer and use it in GitHub Desktop.
Set scroll to percentage
This file contains hidden or 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
const container = document.getElementById('container') | |
const percentage = 50 | |
// getComputedStyle in case container has borders | |
const containerWidth = parseInt(getComputedStyle(container, null).width, 10) | |
container.scrollLeft = ((container.scrollWidth - containerWidth) / 100 ) * percentage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment