Created
October 1, 2018 12:58
-
-
Save kweij/5a0eac4e68e80950c937b6eca10681cb to your computer and use it in GitHub Desktop.
JavaScript-only fix for the background scrolling in Bootstrap modals on iOS (Safari)
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
let previousScrollY = 0; | |
$(document).on('show.bs.modal', () => { | |
previousScrollY = window.scrollY; | |
$('html').addClass('modal-open').css({ | |
marginTop: -previousScrollY, | |
overflow: 'hidden', | |
left: 0, | |
right: 0, | |
top: 0, | |
bottom: 0, | |
position: 'fixed', | |
}); | |
}).on('hidden.bs.modal', () => { | |
$('html').removeClass('modal-open').css({ | |
marginTop: 0, | |
overflow: 'visible', | |
left: 'auto', | |
right: 'auto', | |
top: 'auto', | |
bottom: 'auto', | |
position: 'static', | |
}); | |
window.scrollTo(0, previousScrollY); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oooh! Finaly i found working solution! Thx!