Jquery – jqModal displaying incorrectly in Mobile Safari


I have a jQModal window on my site that has its content populated by an Ajax call. It works fine in all of the desktop browsers, but it fails in Mobile Safari on the iPhone.

The overlay and the window itself are displayed on the top of the body of the page, rather than covering the iPhone viewport. If you scroll up, you can see the window and the overlay positioned as in any other browser. This is especially problematic because, for a user of Mobile Safari, once they scroll down and click to pull up the modal window, there is no response whatsoever – the part of the screen with the modal window is completely invisible to the user.

I'm pretty sure this is because jqModal uses "position: fixed" in its CSS, which is effd on the iPhone for various reasons. Here's a good blog post describing why: http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/

I've looked at some of the other libraries for modal windows (such as BlockUI) and they have the same issue in Mobile Safari. Does anyone know how to modify the jqModal js/css to fix this? Cheers

Best Solution

Maybe try something like this to position the modal div?

Via Jon Brisbin

function showModal() { 
  var win_y = $(window).height(); 
  var scroll_y = $(window).scrollTop(); 
  $("#modal_div").css({ top: scroll_y + "px" }); 

var showTimer = false; 
function maybeShowModal(evt) { 
  if ( showTimer ) { 
    clearTimeout( showTimer ); 
  showTimer = setTimeout( showModal, 175 ); 

$(window).bind( "scroll", maybeShowModal );