Skip to content

Instantly share code, notes, and snippets.

@halfempty
Created February 4, 2015 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halfempty/4be2da472f5ac870360b to your computer and use it in GitHub Desktop.
Save halfempty/4be2da472f5ac870360b to your computer and use it in GitHub Desktop.
Workaround to prevent under-layer scrolling on iOS
var myScrollTop = 0;
jQuery.fn.openLightbox = function() {
if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
myScrollTop = $('body').scrollTop();
var wpadminbar = 0;
if ($('#wpadminbar').length != 0) {
wpadminbar = $('#wpadminbar').outerHeight();
}
thisOffset = myScrollTop - wpadminbar;
offsetString = "-" + thisOffset + "px";
$('.content-area').css({
'top': offsetString,
'position':'fixed'
});
}
}
jQuery.fn.closeLightbox = function() {
if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
$('.content-area').css({
'top': "auto",
'position':'static'
});
$( "body" ).scrollTop( myScrollTop );
myScrollTop = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment