亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery遮罩層實(shí)現(xiàn)方法實(shí)例詳解(附遮罩層插件)

 更新時(shí)間:2015年12月08日 10:26:14   作者:三月軟件工作室  
這篇文章主要介紹了jQuery遮罩層實(shí)現(xiàn)方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了jQuery遮罩層樣式及功能實(shí)現(xiàn)技巧,并附帶分析了一個(gè)簡(jiǎn)單jQuery遮罩層插件實(shí)現(xiàn)方法,需要的朋友可以參考下

本文實(shí)例分析了jQuery遮罩層實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

1 背景半透明遮罩層樣式

需要一個(gè)黑色(當(dāng)然也可以其他)背景,且須設(shè)置為絕對(duì)定位,以下是項(xiàng)目中用到的css樣式:

/* 半透明的遮罩層 */
#overlay {
  background: #000;
  filter: alpha(opacity=50); /* IE的透明度 */
  opacity: 0.5; /* 透明度 */
  display: none;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  z-index: 100; /* 此處的圖層要大于頁(yè)面 */
  display:none;
}

2 jQuery實(shí)現(xiàn)遮罩

/* 顯示遮罩層 */
function showOverlay() {
  $("#overlay").height(pageHeight());
  $("#overlay").width(pageWidth());
  // fadeTo第一個(gè)參數(shù)為速度,第二個(gè)為透明度
  // 多重方式控制透明度,保證兼容性,但也帶來(lái)修改麻煩的問(wèn)題
  $("#overlay").fadeTo(200, 0.5);
}
/* 隱藏覆蓋層 */
function hideOverlay() {
  $("#overlay").fadeOut(200);
}
/* 當(dāng)前頁(yè)面高度 */
function pageHeight() {
  return document.body.scrollHeight;
}
/* 當(dāng)前頁(yè)面寬度 */
function pageWidth() {
  return document.body.scrollWidth;
}

3 提示框

遮罩的目的無(wú)非讓人無(wú)法操作內(nèi)容,突出提示框,而提示框可參考上面的制作,z-index比遮罩層更高便可。主要問(wèn)題是,如何控制提示框在瀏覽器居中。

/* 定位到頁(yè)面中心 */
function adjust(id) {
  var w = $(id).width();
  var h = $(id).height();
  var t = scrollY() + (windowHeight()/2) - (h/2);
  if(t < 0) t = 0;
  var l = scrollX() + (windowWidth()/2) - (w/2);
  if(l < 0) l = 0;
  $(id).css({left: l+'px', top: t+'px'});
}
//瀏覽器視口的高度
function windowHeight() {
  var de = document.documentElement;
  return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
}
//瀏覽器視口的寬度
function windowWidth() {
  var de = document.documentElement;
  return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth
}
/* 瀏覽器垂直滾動(dòng)位置 */
function scrollY() {
  var de = document.documentElement;
  return self.pageYOffset || (de && de.scrollTop) || document.body.scrollTop;
}
/* 瀏覽器水平滾動(dòng)位置 */
function scrollX() {
  var de = document.documentElement;
  return self.pageXOffset || (de && de.scrollLeft) || document.body.scrollLeft;
}

補(bǔ)充:

jQuery簡(jiǎn)單遮罩層插件:

jQuery代碼:

(function ($) {
  $.fn.ShowMask = function (options) {
    var defaults = {
      top: 150,
      left: 200
    }
    var options = $.extend(defaults, options);
    $("html").append('<div id="ui-mask"></div><div id="ui-mask-div" style="z-index: 99999;position: fixed;top:' + options.top + 'px;left:' + options.left + 'px;"><img src="Images/ui-loading.gif" alt="" /><span>操作正在進(jìn)行中,請(qǐng)耐心等待......</span></div>')
    _this_ = $("#ui-mask");
    _this_.height($(document).height())
    _this_.show();
  };
  $.fn.HideMask = function (options) {
    _this_ = $("#ui-mask");
    _this_.remove();
  };
})(jQuery);

css樣式:

#ui-mask
{
  background-color: #666;
  position: absolute;
  z-index: 9999;
  left: 0;
  top: 0;
  display: none;
  width: 100%;
  height: 100%;
  opacity: 0.5;
  filter: alpha(opacity=50);
  -moz-opacity: 0.5;
}
#ui-mask-div img
{
  width: 50px;
  height: 50px;
  float: left;
}
#ui-mask-div span
{
  height: 50px;
  line-height: 50px;
  display: block;
  float: left;
  color: Red;
  font-weight: bold;
  margin-left: 5px;
}

使用方法:

function btn_save()
{
  $(this).ShowMask();
  $.post('url',null,function(d,s){
    $(this).HideMask();
  });
}

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論