jquery - Javascript: Disable iOS scroll-to-top when status bar is tapped -


i've got site, , want disable scrolling when lightbox pops up, , re-enable when lightbox closed. i've got this:

document.ontouchmove = function(e){     if (stopscroll) {         e.preventdefault();     } } 

which works great manual scrolling, user can still tap status bar , taken top of page (and lightbox isn't centred anymore, or worse still, totally off page). i'm using jquery mobile. how can temporarily disable functionality in ios?

i don't believe possible. better solution problem prevent lightbox breaking when scrolling occurs changing lightbox position fixed instead of absolute:

</style> .centered {   position: fixed;   top: 50%;   left: 50%;   margin-top: -50px;   margin-left: -50px;   background:#ccc;   width:100px;   height:100px; } </style> <div class="centered">i won't scroll off page</div> 

another option check scroll event , restore original position:

$('.show_popup').on('click', function(){     var position= $(window).scrolltop(); // save pos             // show popup         $(window).scroll(function(){         $(window).scrolltop(position); // restore pos on scroll     }); });  $('.hide_popup').on('click', function(){     $(window).off(); // remove handler }); 

example: jsfiddle


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -