BlockUI positioning on the page not the screen

馋奶兔 提交于 2020-01-15 10:16:33

问题


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); 

});

回答1:


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;    
});


来源:https://stackoverflow.com/questions/10581079/blockui-positioning-on-the-page-not-the-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!