Last active
July 7, 2019 14:08
-
-
Save ahmedam55/0fb36f34957dd6c71a0fada3cf4fd7ac to your computer and use it in GitHub Desktop.
Prevent scroll on IOS
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
.no-scroll { | |
overflow: hidden; | |
position: fixed; | |
} |
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
export const toggleScroll = visible => { | |
const htmlElment = document.documentElement | |
if (visible) { | |
htmlElment.style.top = `-${htmlElment.scrollTop}px` | |
htmlElment.classList.add('no-scroll') | |
} else { | |
const topOffset = Math.abs(parseInt(htmlElment.style.top, 10)) | |
htmlElment.classList.remove('no-scroll') | |
htmlElment.style.top = null | |
htmlElment.scrollTop = topOffset | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment