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

jQuery超簡單遮罩層實(shí)現(xiàn)方法示例

 更新時(shí)間:2018年09月06日 12:18:42   作者:luyaran  
這篇文章主要介紹了jQuery超簡單遮罩層實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了jQuery遮罩層相關(guān)屬性樣式動態(tài)控制操作技巧,需要的朋友可以參考下

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

在開發(fā)中,為了避免二次提交,遮罩層的運(yùn)用越來越普遍

看了很多代碼,下面跟大家分享一下我認(rèn)為最簡單的遮罩層實(shí)現(xiàn)方式:

1.樣式如下設(shè)置:

CSS代碼:

<style type="text/css">
  .mask {
      position: absolute; top: 0px; filter: alpha(opacity=60); background-color: #777;
      z-index: 1002; left: 0px;
      opacity:0.5; -moz-opacity:0.5;
      display:none;
    }
</style>

其中: opacity:0.5;適用于IE, -moz-opacit:0.5;適用于火狐;你只需要都加上,便可以火狐和IE下都可以使用。

2.指定層的高度、和寬度。

js代碼

<script type="text/javascript">
  //兼容火狐、IE8
  //顯示遮罩層
  function showMask(){
    $("#mask").css("height",$(document).height());
    $("#mask").css("width",$(document).width());
    $("#mask").show();
  }
  //隱藏遮罩層
  function hideMask(){
    $("#mask").hide();
  }
</script>

3.在<body>中加入如下代碼,然后就可以看效果了:

html代碼

<div id="mask" class="mask"></div>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="showMask()" >點(diǎn)我顯示遮罩層</a><br />

4.使用方法:

在ajax提交表單后,加上showMask方法,數(shù)據(jù)返回后,加上hideMask()

需要的親們可以根據(jù)自己需求,在遮罩層上面加一些提示信息

可以使用在線HTML/CSS/JavaScript前端代碼調(diào)試運(yùn)行工具http://tools.jb51.net/code/WebCodeRun測試運(yùn)行上述代碼效果(不要忘記加入jQuery.js文件)。

或者可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun測試運(yùn)行如下完整代碼(為方便測試效果,代碼做了部分改進(jìn)):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>www.dbjr.com.cn jQuery遮罩層</title>
<style type="text/css">
  .mask {
      position: absolute; top: 0px; filter: alpha(opacity=60); background-color: #777;
      z-index: 1; left: 0px;
      opacity:0.5; -moz-opacity:0.5;
      display:none;
    }
  .msg {
    width: 300px;
    height: 200px;
    color: #3c763d;
    background-color: #dff0d8;
    border-radius: 4px;
    padding: 15px;
    position: absolute;
    top: 0;
    text-align: center;
    margin: 0 auto;
    z-index: 999;
    left: 50%;
    margin-left: -150px;
    display:none;
    }
</style>
</head>
<body>
<div id="mask" class="mask" onclick="hideMask()"></div>
<div align="center" class="msg">提示信息</div>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="showMask()" >點(diǎn)我顯示遮罩層</a><br />
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
  //兼容火狐、IE8
  //顯示遮罩層
  function showMask(){
    $("#mask").css("height",$(document).height());
    $("#mask").css("width",$(document).width());
    $("#mask").show();
    $(".msg").show();
  }
  //隱藏遮罩層
  function hideMask(){
    $("#mask").hide();
    $(".msg").hide();
  }
</script>
</body>
</html>

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery窗口操作技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)

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

相關(guān)文章

最新評論