Web页面中使用遮罩层,可防止重复操作,提示loading;也可以模拟弹出模态窗口。
实现思路:一个DIV作为遮罩层,一个DIV显示loading动态GIF图片。在下面的示例代码中,同时展示了如何在iframe子页面中调用显示和隐藏遮罩层。
示例代码:
index.html
1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4 <meta charset="utf-8"> 5 <meta http-equiv="X-UA-Commpatible" content="IE=edge"> 6 <title>HTML遮罩层</title> 7 <link rel="stylesheet" href="css/index.css"> 8 </head> 9 <body>10 <div class="header" id="header">11 <div class="title-outer">12 <span class="title">13 HTML遮罩层使用14 </span>15 </div>16 </div>17 <div class="body" id="body">18 <iframe id="iframeRight" name="iframeRight" width="100%" height="100%"19 scrolling="no" frameborder="0"20 style="border: 0px;margin: 0px; padding: 0px; width: 100%; height: 100%;overflow: hidden;"21 onload="rightIFrameLoad(this)" src="body.html"></iframe>22 </div>23 24 <!-- 遮罩层DIV -->25 <div id="overlay" class="overlay"></div>26 <!-- Loading提示 DIV -->27 <div id="loadingTip" class="loading-tip">28 <img src="/static/imghwm/default1.png" data-src="images/loading.gif" class="lazy" / alt="在HTML中实现和使用遮罩层_html/css_WEB-ITnose" >29 </div>30 31 <!-- 模拟模态窗口DIV -->32 <div class="modal" id="modalDiv"></div>33 34 <script type='text/javascript' src="js/jquery-1.10.2.js"></script>35 <script type="text/javascript" src="js/index.js"></script>36 </body>37 </html>
index.css
1 * { 2 margin: 0; 3 padding: 0; 4 } 5 6 html, body { 7 width: 100%; 8 height: 100%; 9 font-size: 14px;10 }11 12 div.header {13 width: 100%;14 height: 100px;15 border-bottom: 1px dashed blue;16 }17 18 div.title-outer {19 position: relative;20 top: 50%;21 height: 30px;22 }23 span.title {24 text-align: left;25 position: relative;26 left: 3%;27 top: -50%;28 font-size: 22px;29 }30 31 div.body {32 width: 100%;33 }34 .overlay {35 position: absolute;36 top: 0px;37 left: 0px;38 z-index: 10001;39 display:none;40 filter:alpha(opacity=60);41 background-color: #777;42 opacity: 0.5;43 -moz-opacity: 0.5;44 }45 .loading-tip {46 z-index: 10002;47 position: fixed;48 display:none;49 }50 .loading-tip img {51 width:100px;52 height:100px;53 }54 55 .modal {56 position:absolute;57 width: 600px;58 height: 360px;59 border: 1px solid rgba(0, 0, 0, 0.2);60 box-shadow: 0px 3px 9px rgba(0, 0, 0, 0.5);61 display: none;62 z-index: 10003;63 border-radius: 6px;64 }
index.js
1 function rightIFrameLoad(iframe) { 2 var pHeight = getWindowInnerHeight() - $('#header').height() - 5; 3 4 $('div.body').height(pHeight); 5 console.log(pHeight); 6 7 } 8 9 // 浏览器兼容 取得浏览器可视区高度 10 function getWindowInnerHeight() { 11 var winHeight = window.innerHeight 12 || (document.documentElement && document.documentElement.clientHeight) 13 || (document.body && document.body.clientHeight); 14 return winHeight; 15 16 } 17 18 // 浏览器兼容 取得浏览器可视区宽度 19 function getWindowInnerWidth() { 20 var winWidth = window.innerWidth 21 || (document.documentElement && document.documentElement.clientWidth) 22 || (document.body && document.body.clientWidth); 23 return winWidth; 24 25 } 26 27 /** 28 * 显示遮罩层 29 */ 30 function showOverlay() { 31 // 遮罩层宽高分别为页面内容的宽高 32 $('.overlay').css({'height':$(document).height(),'width':$(document).width()}); 33 $('.overlay').show(); 34 } 35 36 /** 37 * 显示Loading提示 38 */ 39 function showLoading() { 40 // 先显示遮罩层 41 showOverlay(); 42 // Loading提示窗口居中 43 $("#loadingTip").css('top', 44 (getWindowInnerHeight() - $("#loadingTip").height()) / 2 + 'px'); 45 $("#loadingTip").css('left', 46 (getWindowInnerWidth() - $("#loadingTip").width()) / 2 + 'px'); 47 48 $("#loadingTip").show(); 49 $(document).scroll(function() { 50 return false; 51 }); 52 } 53 54 /** 55 * 隐藏Loading提示 56 */ 57 function hideLoading() { 58 $('.overlay').hide(); 59 $("#loadingTip").hide(); 60 $(document).scroll(function() { 61 return true; 62 }); 63 } 64 65 /** 66 * 模拟弹出模态窗口DIV 67 * @param innerHtml 模态窗口HTML内容 68 */ 69 function showModal(innerHtml) { 70 // 取得显示模拟模态窗口用DIV 71 var dialog = $('#modalDiv'); 72 73 // 设置内容 74 dialog.html(innerHtml); 75 76 // 模态窗口DIV窗口居中 77 dialog.css({ 78 'top' : (getWindowInnerHeight() - dialog.height()) / 2 + 'px', 79 'left' : (getWindowInnerWidth() - dialog.width()) / 2 + 'px' 80 }); 81 82 // 窗口DIV圆角 83 dialog.find('.modal-container').css('border-radius','6px'); 84 85 // 模态窗口关闭按钮事件 86 dialog.find('.btn-close').click(function(){ 87 closeModal(); 88 }); 89 90 // 显示遮罩层 91 showOverlay(); 92 93 // 显示遮罩层 94 dialog.show(); 95 } 96 97 /** 98 * 模拟关闭模态窗口DIV 99 */100 function closeModal() {101 $('.overlay').hide();102 $('#modalDiv').hide();103 $('#modalDiv').html('');104 }
body.html
1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4 <meta charset="utf-8"> 5 <meta http-equiv="X-UA-Commpatible" content="IE=edge"> 6 <title>body 页面</title> 7 <style type="text/css"> 8 * { 9 margin: 0;10 padding: 0;11 }12 13 html, body {14 width: 100%;15 height: 100%;16 }17 18 .outer {19 width: 200px;20 height: 120px;21 position: relative;22 top: 50%;23 left: 50%;24 }25 26 .inner {27 width: 200px;28 height: 120px;29 position: relative;30 top: -50%;31 left: -50%;32 }33 34 .button {35 width: 200px;36 height: 40px;37 position: relative;38 }39 40 .button#btnShowLoading {41 top: 0;42 }43 44 .button#btnShowModal {45 top: 30%;46 }47 48 </style>49 <script type="text/javascript">50 51 function showOverlay() {52 // 调用父窗口显示遮罩层和Loading提示53 window.top.window.showLoading();54 55 // 使用定时器模拟关闭Loading提示56 setTimeout(function() {57 window.top.window.hideLoading();58 }, 3000);59 60 }61 62 function showModal() {63 // 调用父窗口方法模拟弹出模态窗口64 window.top.showModal($('#modalContent').html());65 }66 67 </script>68 </head>69 <body>70 <div class='outer'>71 <div class='inner'>72 <button id='btnShowLoading' class='button' onclick='showOverlay();'>点击弹出遮罩层</button>73 <button id='btnShowModal' class='button' onclick='showModal();'>点击弹出模态窗口</button>74 </div>75 </div>76 77 <!-- 模态窗口内容DIV,将本页面DIV内容设置到父窗口DIV上并模态显示 -->78 <div id='modalContent' style='display: none;'>79 <div class='modal-container' style='width: 100%;height: 100%;background-color: white;'>80 <div style='width: 100%;height: 49px;position: relative;left: 50%;top: 50%;'>81 <span style='font-size: 36px; width: 100%; text-align:center; display: inline-block; position:inherit; left: -50%;top: -50%;'>模态窗口1</span>82 </div>83 <button class='btn-close' style='width: 100px; height: 30px; position: absolute; right: 30px; bottom: 20px;'>关闭</button>84 </div>85 </div>86 <script type='text/javascript' src="js/jquery-1.10.2.js"></script>87 </body>88 </html>
运行结果
初始化
显示遮罩层和Loading提示
显示遮罩层和模拟弹出模态窗口
END

HTML의 미래 트렌드는 의미론 및 웹 구성 요소이며 CSS의 미래 트렌드는 CSS-In-JS 및 CSShoudini이며, JavaScript의 미래 트렌드는 WebAssembly 및 서버리스입니다. 1. HTML 시맨틱은 접근성과 SEO 효과를 향상시키고 웹 구성 요소는 개발 효율성을 향상 시키지만 브라우저 호환성에주의를 기울여야합니다. 2. CSS-in-JS는 스타일 관리 유연성을 향상 시키지만 파일 크기를 증가시킬 수 있습니다. CSShoudini는 CSS 렌더링의 직접 작동을 허용합니다. 3. Webosembly는 브라우저 애플리케이션 성능을 최적화하지만 가파른 학습 곡선을 가지고 있으며 서버리스는 개발을 단순화하지만 콜드 스타트 문제의 최적화가 필요합니다.

웹 개발에서 HTML, CSS 및 JavaScript의 역할은 다음과 같습니다. 1. HTML은 웹 페이지 구조를 정의하고, 2. CSS는 웹 페이지 스타일을 제어하고 3. JavaScript는 동적 동작을 추가합니다. 그들은 함께 현대 웹 사이트의 프레임 워크, 미학 및 상호 작용을 구축합니다.

HTML의 미래는 무한한 가능성으로 가득합니다. 1) 새로운 기능과 표준에는 더 많은 의미 론적 태그와 WebComponents의 인기가 포함됩니다. 2) 웹 디자인 트렌드는 반응적이고 접근 가능한 디자인을 향해 계속 발전 할 것입니다. 3) 성능 최적화는 반응 형 이미지 로딩 및 게으른로드 기술을 통해 사용자 경험을 향상시킬 것입니다.

웹 개발에서 HTML, CSS 및 JavaScript의 역할은 다음과 같습니다. HTML은 컨텐츠 구조를 담당하고 CSS는 스타일을 담당하며 JavaScript는 동적 동작을 담당합니다. 1. HTML은 태그를 통해 웹 페이지 구조와 컨텐츠를 정의하여 의미를 보장합니다. 2. CSS는 선택기와 속성을 통해 웹 페이지 스타일을 제어하여 아름답고 읽기 쉽게 만듭니다. 3. JavaScript는 스크립트를 통해 웹 페이지 동작을 제어하여 동적 및 대화식 기능을 달성합니다.

Htmlisnotaprogramminglanguage; itisamarkuplanguage.1) htmlstructuresandformatswebcontentusingtags.2) itworksporstylingandjavaScriptOfforIncincivity, WebDevelopment 향상.

HTML은 웹 페이지 구조를 구축하는 초석입니다. 1. HTML은 컨텐츠 구조와 의미론 및 사용 등을 정의합니다. 태그. 2. SEO 효과를 향상시키기 위해 시맨틱 마커 등을 제공합니다. 3. 태그를 통한 사용자 상호 작용을 실현하려면 형식 검증에주의를 기울이십시오. 4. 자바 스크립트와 결합하여 동적 효과를 달성하기 위해 고급 요소를 사용하십시오. 5. 일반적인 오류에는 탈수 된 레이블과 인용되지 않은 속성 값이 포함되며 검증 도구가 필요합니다. 6. 최적화 전략에는 HTTP 요청 감소, HTML 압축, 시맨틱 태그 사용 등이 포함됩니다.

HTML은 웹 페이지를 작성하는 데 사용되는 언어로, 태그 및 속성을 통해 웹 페이지 구조 및 컨텐츠를 정의합니다. 1) HTML과 같은 태그를 통해 문서 구조를 구성합니다. 2) 브라우저는 HTML을 구문 분석하여 DOM을 빌드하고 웹 페이지를 렌더링합니다. 3) 멀티미디어 기능을 향상시키는 HTML5의 새로운 기능. 4) 일반적인 오류에는 탈수 된 레이블과 인용되지 않은 속성 값이 포함됩니다. 5) 최적화 제안에는 시맨틱 태그 사용 및 파일 크기 감소가 포함됩니다.

WebDevelopmentReliesonHtml, CSS 및 JavaScript : 1) HtmlStructuresContent, 2) CSSSTYLESIT, 및 3) JAVASCRIPTADDSINGINTERACTIVITY, BASISOFMODERNWEBEXPERIENCES를 형성합니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경
