Skip to content

Instantly share code, notes, and snippets.

@MikelArnaiz
Created March 30, 2021 19:30
Show Gist options
  • Save MikelArnaiz/fa8bc91565d83b49fbfe71f824f147f6 to your computer and use it in GitHub Desktop.
Save MikelArnaiz/fa8bc91565d83b49fbfe71f824f147f6 to your computer and use it in GitHub Desktop.
Set scroll to percentage
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