好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

如何阻止遮罩层后页面滚动的实例

一:页面会初始化到顶端,而后静止
css代码:

.ovfHiden{overflow: hidden;height: 100%;} 

jquery:

$(".header_right").click(function(){$('html,body').addClass('ovfHiden'); //使网页不可滚动
   $(".searchbox").show();
 })
 $(".yg-close").click(function(){
   $('html,body').removeClass('ovfHiden'); //使网页恢复可滚
   $(".searchbox").hide();
 }) 

二:页面正常静止
1.打开新页面时需要禁止鼠标滚轮,禁止页面滑动;
在调用显示层时加上这句js代码就可以了:

document.documentElement.style.overflow = "hidden"; 


关闭层的时间别忘了在加上这句:

document.documentElement.style.overflow = "scroll"; 


2.设置滚轮原来位置

var top_temp = $(document).scrollTop()||document.documentElement.scrollTop || document.body.scrollTop;
window.parent.scrollTo(0,top_value); 

以上就是如何阻止遮罩层后页面滚动的实例的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于如何阻止遮罩层后页面滚动的实例的详细内容...

  阅读:51次