Created
December 3, 2019 08:41
-
-
Save webdesignberlin/20885800421eb2bf7e9b41985ed50a72 to your computer and use it in GitHub Desktop.
Prevent toxic scroll behavior of ios on overflow components
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
.ios-body-fixed { | |
position: fixed; | |
width: 100%; | |
height: 100%; | |
} |
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
const body = document.body; | |
const bodyFixed = (activate = false) => { | |
if (activate) { | |
body.classList.add('ios-body-fixed'); | |
} else { | |
body.classList.remove('ios-body-fixed'); | |
} | |
}; | |
[...document.querySelectorAll('input')].forEach(el => el.addEventListener('focus', () => bodyFixed(true))); | |
[...document.querySelectorAll('input')].forEach(el => el.addEventListener('blur', () => bodyFixed(false))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment