Search code examples
jquerypositionblockui

BlockUI positioning on the page not the screen


I have used this plugin before but now the blockui is not positioning correctly on the page. on the screen it's ok like 40% from the top but the problem is with the page. it is scrolling all the way up to the top.

if I have a button in the moddle of the page and I click on it to start the blockui the page will scrool back to the top. and I dont know why

here is the html:

<div class="btn" id="block">
   <a href="#"><span>to buy tickets</span></a>
</div>
<div id="blockmsg">
  <a href="#" id="x"><img src="images/x.png" alt="x to close the window"/></a>
  <div class="blockmsg">
    <a href="#" class="hadran"><span>hadran.co.il</span></a>
    <a href="#" class="opera"><span>opera house</span></a>
    <div style="clear: both;height: 15px;"></div>
    <div class="btnhand">
      <a href="#"><span>join facebook</span></a>
    </div>
  </div>
</div>



the css:

div.btn{
  width: 266px;
  margin: 0 auto;
  height: 56px;
}
#blockmsg{
  position: relative;
  padding-top: 30px;
  display: none;
  width: 400px;
  z-index: 100000;
}



the jquery:

$('#block').click(function() { 

  $.blockUI({ 
      message: $('#blockmsg'), 
      fadeIn: 700,
      fadeOut: 700,
      centerX: true,
      centerY: true,
      css: { 
      backgroundColor: 'transparent',
      border: 'none',
      cursor: 'default'

    } 
  }); 
  $('#x').attr('title','Click to unblock').click($.unblockUI);
  //setTimeout($.unblockUI, 2000); 

});

Solution

  • Try adding return false; to the end of the click handler to prevent the browser from also doing the default action when you click the link, which is to go to the # url.

    i.e. change your jQuery to:

    $('#block').click(function() { 
    
      $.blockUI({ 
        // ... (same as before) 
      }); 
      $('#x').attr('title','Click to unblock').click($.unblockUI);
    
      return false;    
    });