The problem, as many people have described, is related to:
position:fixed
Now, if you open the modal, you will be thrown into the page title ... To avoid this, I use this solution (next to @ Will's).
First make sure your iOS device:
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
If the device is iOS - add the class of the iOS device to the body:
if (iOS) { $('body').addClass('iOS-device'); }
Make a variable to save the scroll position:
var scrollPosition;
Now we find the show.bs.modal event and set the top property of the iOS device for a negative scrollPosition:
$('.modal').on('show.bs.modal', function() { scrollPosition = $(window).scrollTop(); $('.iOS-device').css('top', -scrollPosition); });
Then define the hide.bs.modal event, remove the modal-open class, reset the top value of the iOS device and scroll through the document until it was before the modal was opened:
$('.modal').on('hide.bs.modal', function() { $('.iOS-device').removeClass('modal-open'); $('.iOS-device').css('top', 0); $(document).scrollTop(scrollPosition); });
And the full code:
( function() { var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; if (iOS) { $('body').addClass('iOS-device'); } var scrollPosition; $('.modal').on('show.bs.modal', function() { scrollPosition = $(window).scrollTop(); $('.iOS-device').css('top', -scrollPosition); }); $('.modal').on('hide.bs.modal', function() { $('.iOS-device').removeClass('modal-open'); $('.iOS-device').css('top', 0); $(document).scrollTop(scrollPosition); }); })();
CSS
body.modal-open.iOS-device { position: fixed; width: 100%; }
Roland Ruul Nov 07 '17 at 11:03 on 2017-11-07 11:03
source share