Skip to content

Instantly share code, notes, and snippets.

@chekit
Forked from mhammonds/HideMobileAddressBar.js
Last active October 27, 2015 22:21
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 chekit/cb5ff345538f81cd019f to your computer and use it in GitHub Desktop.
Save chekit/cb5ff345538f81cd019f to your computer and use it in GitHub Desktop.
Hide Browser Address Bar - Android + iPhone
//На одном из проектов оказалось, что достаточно добавить body position:fixed
//Ситуация была: на мобильных меню при открытии становилось fixed, но при прокрутке снизу из-за адресной строки появлялся "провал"
//Так же для манипуляции меню к body добавлялся класс .show-nav
//В моей ситуации оказалось достаточно просто добавить в show-nav position: fixed (пофиксить body)
function hideAddressBar()
{
if(!window.location.hash)
{
if(document.height < window.outerHeight)
{
document.body.style.height = (window.outerHeight + 50) + 'px';
}
setTimeout( function(){ window.scrollTo(0, 1); }, 50 );
}
}
window.addEventListener("load", function(){ if(!window.pageYOffset){ hideAddressBar(); } } );
window.addEventListener("orientationchange", hideAddressBar );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment