Created
February 4, 2015 17:51
-
-
Save halfempty/4be2da472f5ac870360b to your computer and use it in GitHub Desktop.
Workaround to prevent under-layer scrolling on iOS
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
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