欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

1 背景半透明遮罩層樣式

需要一個黑色(當然也可以其他)背景,且須設置為絕對定位,以下是項目中用到的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; /* 此處的圖層要大于頁面 */
  display:none;
}

2 jQuery實現(xiàn)遮罩

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

3 提示框

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

/* 定位到頁面中心 */
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
}
/* 瀏覽器垂直滾動位置 */
function scrollY() {
  var de = document.documentElement;
  return self.pageYOffset || (de && de.scrollTop) || document.body.scrollTop;
}
/* 瀏覽器水平滾動位置 */
function scrollX() {
  var de = document.documentElement;
  return self.pageXOffset || (de && de.scrollLeft) || document.body.scrollLeft;
}

補充:

jQuery簡單遮罩層插件:

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>操作正在進行中,請耐心等待......</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();
  });
}

希望本文所述對大家jQuery程序設計有所幫助。

相關文章

最新評論