国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

HTML實現遮罩層的方法 HTML中如何使用遮罩層

2020-03-24 16:53:33
字體:
來源:轉載
供稿:網友
這篇文章主要為大家詳細介紹了HTML實現遮罩層的方法,Web頁面中使用遮罩層,可防止重復操作,那么如何在HTML中使用遮罩層?感興趣的小伙伴們可以參考一下

Web頁面中使用遮罩層,可防止重復操作,提示loading;也可以模擬彈出模態窗口。

實現思路:一個p作為遮罩層,一個p顯示loading動態GIF圖片。在下面的示例代碼中,同時展示了如何在iframe子頁面中調用顯示和隱藏遮罩層。

示例代碼:

index.html

XML/HTML Code復制內容到剪貼板

 !DOCTYPE html  html lang= zh-CN  head  meta charset= utf-8  meta http-equiv= X-UA-Commpatible content= IE=edge  title HTML遮罩層 /title  link rel= stylesheet href= css/index.css  /head  body  p >

index.css

CSS Code復制內容到剪貼板

* {  margin: 0;  padding: 0; html, body {  width: 100%;  height: 100%;  font-size: 14px; p.header {  width: 100%;  height: 100px;  border-bottom: 1px dashed blue; p.title-outer {  position: relative;  top: 50%;  height: 30px; span.title {  text-align: left;  position: relative;  left: 3%;  top: -50%;  font-size: 22px; p.body {  width: 100%; .overlay {  position: absolute;  top: 0px;  left: 0px;  z-index: 10001;  display:none;  filter:alpha(opacity=60);  background-color: #777;  opacity: 0.5;  -moz-opacity: 0.5; .loading-tip {  z-index: 10002;  position: fixed;  display:none; .loading-tip img {  width:100px;  height:100px; .modal {  position:absolute;  width: 600px;  height: 360px;  border: 1px solid rgba(0, 0, 0, 0.2);  box-shadow: 0px 3px 9px rgba(0, 0, 0, 0.5);  display: none;  z-index: 10003;  border-radius: 6px; }

index.js

JavaScript Code復制內容到剪貼板

function rightIFrameLoad(iframe) {  var pHeight = getWindowInnerHeight() - $( #header ).height() - 5;  $( p.body ).height(pHeight);  console.log(pHeight); // 瀏覽器兼容 取得瀏覽器可視區高度 function getWindowInnerHeight() {  var winHeight = window.innerHeight  || (document.documentElement document.documentElement.clientHeight)  || (document.body document.body.clientHeight);  return winHeight; // 瀏覽器兼容 取得瀏覽器可視區寬度 function getWindowInnerWidth() {  var winWidth = window.innerWidth  || (document.documentElement document.documentElement.clientWidth)  || (document.body document.body.clientWidth);  return winWidth;  * 顯示遮罩層 function showOverlay() {  // 遮罩層寬高分別為頁面內容的寬高  $( .overlay ).css({ height :$(document).height(), width :$(document).width()});  $( .overlay ).show();  * 顯示Loading提示 function showLoading() {  // 先顯示遮罩層  showOverlay();  // Loading提示窗口居中  $( #loadingTip ).css( top ,  (getWindowInnerHeight() - $( #loadingTip ).height()) / 2 + px  $( #loadingTip ).css( left ,  (getWindowInnerWidth() - $( #loadingTip ).width()) / 2 + px  $( #loadingTip ).show();  $(document).scroll(function() {  return false;  });  * 隱藏Loading提示 function hideLoading() {  $( .overlay ).hide();  $( #loadingTip ).hide();  $(document).scroll(function() {  return true;  });  * 模擬彈出模態窗口p  * @param innerHtml 模態窗口HTML內容 function showModal(innerHtml) {  // 取得顯示模擬模態窗口用p  var dialog = $( #modalp  // 設置內容  dialog.html(innerHtml);  // 模態窗口p窗口居中  dialog.css({  top : (getWindowInnerHeight() - dialog.height()) / 2 + px ,  left : (getWindowInnerWidth() - dialog.width()) / 2 + px  });  // 窗口p圓角  dialog.find( .modal-container ).css( border-radius , 6px  // 模態窗口關閉按鈕事件  dialog.find( .btn-close ).click(function(){  closeModal();  });  // 顯示遮罩層  showOverlay();  // 顯示遮罩層  dialog.show();  * 模擬關閉模態窗口p function closeModal() {  $( .overlay ).hide();  $( #modalp ).hide();  $( #modalp ).html( }

body.html

XML/HTML Code復制內容到剪貼板

 !DOCTYPE html  html lang= zh-CN  head  meta charset= utf-8  meta http-equiv= X-UA-Commpatible content= IE=edge  title body 頁面 /title  style type= text/css  margin: 0;  padding: 0; html, body {  width: 100%;  height: 100%; .outer {  width: 200px;  height: 120px;  position: relative;  top: 50%;  left: 50%; .inner {  width: 200px;  height: 120px;  position: relative;  top: -50%;  left: -50%; .button {  width: 200px;  height: 40px;  position: relative; .button#btnShowLoading {  top: 0; .button#btnShowModal {  top: 30%;  /style  script type= text/javascript  function showOverlay() {  // 調用父窗口顯示遮罩層和Loading提示  window.top.window.showLoading();  // 使用定時器模擬關閉Loading提示  setTimeout(function() {  window.top.window.hideLoading();  }, 3000);  function showModal() {  // 調用父窗口方法模擬彈出模態窗口  window.top.showModal($( #modalContent ).html());  /script  /head  body  p >

運行結果:

初始化

顯示遮罩層和Loading提示

顯示遮罩層和模擬彈出模態窗口

以上就是本文的全部內容,希望對大家的學習有所幫助。

相關推薦:

HTML中使背景圖片自適應瀏覽器大小

以上就是HTML實現遮罩層的方法 HTML中如何使用遮罩層的詳細內容,html教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 修文县| 日照市| 铅山县| 江永县| 田东县| 临高县| 昂仁县| 渝中区| 盈江县| 河北省| 辰溪县| 武鸣县| 古浪县| 贡山| 贵南县| 林州市| 信丰县| 阿拉善盟| 灵丘县| 洛南县| 梁山县| 湛江市| 林芝县| 轮台县| 正安县| 江达县| 临漳县| 延吉市| 眉山市| 东城区| 西峡县| 饶河县| 农安县| 通榆县| 马关县| 烟台市| 广州市| 昆明市| 略阳县| 雷山县| 普洱|