Created
October 3, 2019 13:09
-
-
Save lannonbr/b7e6435984aa23a52693c765f071e97b to your computer and use it in GitHub Desktop.
Bug that window.scrollTo running immediately works in firefox, but not chrome, and can be fixed with a setTimeout(callback, 0)
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<style> | |
body { | |
width: 10000px; | |
} | |
h1 { | |
position: relative; | |
display: inline-block; | |
left: 6000px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Hey</h1> | |
<script> | |
// Does not work in Chrome | |
// window.scrollTo({ | |
// left: 6000 | |
// }); | |
// Does work in Chrome | |
setTimeout(() => { | |
window.scrollTo({ | |
left: 6000 | |
}); | |
}, 0); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment