Using a mask layer in Web pages can prevent repeated operations and prompt loading; it can also simulate pop-up modal windows.
Implementation idea: One DIV serves as the mask layer, and one DIV displays the loading dynamic GIF image. In the following sample code, it also shows how to call the display and hiding mask layer in the iframe subpage.
Sample code:
index.html
XML/HTML CodeCopy content to clipboard
-
>
-
<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>
-
<div class="header" id="header">
-
<div class="title-outer">
-
<span class="title">
-
HTML遮罩层使用
-
span>
-
div>
-
div>
-
<div class="body" id="body">
-
<iframe id="iframeRight" name="iframeRight" width="100%" height="100%"
- scrolling="no" frameborder="0"
- style="border: 0px;margin: 0px; padding: 0px; width: 100%; height: 100%;overflow: hidden;"
- onload="rightIFrameLoad(this)" src="body.html">iframe>
-
div>
-
-
-
<div id="overlay" class="overlay">div>
-
-
<div id="loadingTip" class="loading-tip">
-
<img src="images/loading.gif" />
-
div>
-
-
-
<div class="modal" id="modalDiv">div>
-
-
<script type='text/javascript' src="js/jquery-1.10.2.js">script>
-
<script type="text/javascript" src="js/index.js">script>
-
body>
-
html>
index.css
CSS Code复制内容到剪贴板
-
* {
-
margin: 0;
-
padding: 0;
-
}
-
-
html, body {
-
width: 100%;
-
height: 100%;
-
font-size: 14px;
-
}
-
-
div.header {
-
width: 100%;
-
height: 100px;
-
border-bottom: 1px dashed blue;
-
}
-
-
div.title-outer {
-
position: relative;
-
top: 50%;
-
height: 30px;
-
}
-
span.title {
-
text-align: left;
-
position: relative;
-
left: 3%;
-
top: -50%;
-
font-size: 22px;
-
}
-
-
div.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
body.html
XML/HTML CodeCopy content to clipboard
-
>
-
<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() {
-
// Call the parent window to display the mask layer and Loading prompts
-
window.top.window.showLoading();
-
-
// Use a timer to simulate closing the Loading prompt
-
setTimeout(function() {
-
window.top.window.hideLoading();
-
}, 3000);
-
-
}
-
-
function showModal() {
-
// Call the parent window method to simulate a pop-up modal window
-
window.top.showModal($('#modalContent').html());
-
}
-
-
script>
-
head>
-
<body>
-
<div class='outer' >
-
<div class='inner' >
-
<button id='btnShowLoading' class='button' onclick='showOverlay();'>Click to pop up the mask layerbutton>
-
<button id='btnShowModal' class='button' onclick='showModal();'>Click to pop up the modal windowbutton>
-
div>
-
div>
-
-
-
<div id='modalContent' style='display: none;'>
-
<div class='modal- container' style='width: 100%;height: 100%;background-color: white;'>
-
<div style='width: 100%;height: 49px;position: relative;left: 50%;top: 50%;'>
-
<span style='font-size: 36px; width: 100%; text-align:center; display: inline-block; position:inherit; left: -50%;top: -50%;'>模态窗口1span>
-
div>
-
<button class='btn-close' style='width: 100px; height: 30px; position: absolute; right: 30px; bottom: 20px;'>关闭button>
-
div>
-
div>
-
<script type='text/javascript' src="js/jquery-1.10.2.js">script>
-
body>
-
html>
-
运行结果:
初始化
显示遮罩层和Loading提示
显示遮罩层和模拟弹出模态窗口
以上就是本文的全部内容,希望对大家的学习有所帮助。
原文:http://www.cnblogs.com/haoqipeng/p/html-overlay.html