css +js实现遮障层效果


1
/* 2 *使用说明,当需要用户等待时可直接在等待的方法中输入以下方法 3 *IsShow:0不显示 1显示 其他数字为修改样式如当改变窗口大小时遮障层自动适用窗口大小 4 */ 5 $(window).scroll(function () { changeMasker("3") }).resize(function () { changeMasker("3") }); 6 function changeMasker(IsShow) { 7 8 var $windowWidth = $(window).width(); 9 var $windowHeight = $(window).height(); 10 var $maskerBackground = $("#maskerBackground"); 11 var $maskerText; 12 if ($maskerBackground.length <= 0) { 13 var maskerHtml = "<div id='masker' style='display:none;'><div id='maskerBackground' style='background-color: gray; filter: alpha(opacity=80); -moz-opacity: 0.8; -khtml-opacity: 0.3; opacity: 0.8; z-index: 2; position: absolute; left: 0px; top: 0px;'>" + 14 "</div><div id='maskerText' style='position: absolute; width: 250px; height: 185px; line-height: 185px; z-index: 3; filter: alpha(opacity=80); -moz-opacity: 0.8; -khtml-opacity: 0.3; opacity: 0.8; background-image:url(../Contents/Images/loading.gif); '> </div></div>"; 15 $("div:last").after($(maskerHtml)); 16 $maskerBackground = $("#maskerBackground"); 17 $maskerText = $("#maskerText"); 18 } 19 20 if (IsShow == "1") $("#masker").show(); 21 else if (IsShow == "0") $("#masker").hide(); 22 23 $maskerBackground.css({ 'width': $windowWidth, 'height': $windowHeight + $(document).scrollTop() }); 24 $maskerText.css({ 25 'width': $maskerText.width(), 'height': $maskerText.height(), 26 'top': ($windowHeight - $maskerText.height()) / 2 + $(document).scrollTop(), 'left': ($windowWidth - $maskerText.width()) / 2 27 }); 28 }

 

posted @ 2014-12-02 15:05  Man_It  阅读(386)  评论(0)    收藏  举报