DIV CSS 佈局教程網

jquery遮罩層簡單實現
編輯:JQuery特效代碼     
彈出遮罩層

或者到這裡體驗效果:http://hovertree.com/texiao/jquery/11.htm

以前會用到
var screenWidth = $(document).width();//當前窗口寬度
var screenHeight = $(document).height();//當前窗口高度
或者
var screenWidth = $(window).width();//當前窗口寬度
var screenHeight = $(window).height();//當前窗口高度

以前的代碼:
<div style=" display:none" id="zzhovertree"></div>
<script type="text/javascript">
function showUnitInfo()
{
var screenWidth = $(document).width();//當前窗口寬度
var screenHeight = $(document).height();//當前窗口高度

$("#zzhovertree").css({"display":"","position": "fixed","background": "#000","z-index": "1001","-moz-opacity": "0.5","opacity":".50","filter": "alpha(opacity=50)","width":screenWidth,"height":screenHeight});
}
</script>
<a href="javascript:showUnitInfo()">彈出遮罩層</a>



現在不用了,現在的代碼:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>jquery遮罩層簡單實現 - 何問起</title>
<style>body{margin:0px}</style>
<meta charset="utf-8" />
<script type="text/javascript" src="http://hovertree.com/ziyuan/jquery/jquery-1.11.3.min.js"></script>
</head>
<body>
<div style="display:none" id="zzhovertree"></div>
<script type="text/javascript">
function ZZhovertree()
{
$("#zzhovertree").css({"display":"","position": "fixed","left":"0px","top":"0px","background": "#000","z-index": "1001","-moz-opacity": "0.5","opacity":".50","filter": "alpha(opacity=50)","width":"100%","height":"100%"});
}
$("#zzhovertree").on("click", function () { $("#zzhovertree").slideUp()})
</script>
<div style="width:768px;margin:50px auto;">
<a href="javascript:ZZhovertree();">彈出遮罩層</a>
<a href="http://hovertree.com/hvtart/bjae/o5so5i9x.htm">原文</a>
<a href="http://hovertree.com">首頁</a> <a href="http://hovertree.com/texiao/">特效</a>
</div>
<div style="background-color:#959822; width:100%;height:150px;">請點擊本頁面的 彈出遮罩層 鏈接體驗效果</div>
<div style="background-color:Green; width:100%;height:150px;">
hovertree.com
</div>
<div style="width:738px;height:186px;margin:10px auto;">
</div>
<div style="background-color:Red; width:100%;height:150px;">歡迎</div>
<div style="background-color:Yellow; width:100%;height:150px;"><a href="http://hovertree.com/">首頁</a></div>
<div style="background-color:Silver; width:100%;height:150px;">何問起</div>
<div style="background-color:Aqua; width:1336px;height:150px;">hovertree.com</div>
<div style="background-color:Fuchsia; width:100%;height:150px;"><a href="http://hovertree.com/texiao/">更多特效</a></div>
<div style="background-color:Green; width:100%;height:150px;">hovertreetofoot</div>
<div style="background-color:Blue; width:100%;height:150px;"></div>
<div style="background-color:Olive; width:100%;height:350px;">何問起 返回頂部</div>
<div style="background-color:Green; width:100%;height:150px;">HoverTree</div>
<div style="background-color:Purple; width:100%;height:150px;">jquery</div>
<div style="background-color:Green; width:100%;height:150px;"><a href="http://hovertree.com/hvtart/bjae/65358656.htm" target="_blank">原文</a></div>
<div style="background-color:Lime; width:100%;height:150px;">hovertree.com</div>
<div style="background-color:Orange; width:100%;height:150px;">完整代碼</div>
<div style="height:130px;"></div>
</body>
</html>

jquery寫的,使用前需要引用類庫。

先寫一個不顯示的div,當觸發事件時,為這個div添加樣式,高度=當前窗口高度,寬度=當前窗口寬度。


改進代碼:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>jquery遮罩層簡單實現 - 何問起</title>
<style>body{margin:0px}a{color:blue}</style>
<meta charset="utf-8" />
<script type="text/javascript" src="http://hovertree.com/ziyuan/jquery/jquery-1.11.3.min.js"></script>
</head>
<body>
<div style="background-color:#959822; width:100%;height:150px;">
請點擊本頁面的 彈出遮罩層 鏈接體驗效果</div>

<div style="width:768px;margin:50px auto;">
<a href="javascript:ZZhovertree();">彈出遮罩層</a>
<a href="http://hovertree.com/hvtart/bjae/o5so5i9x.htm">原文</a>
<a href="http://hovertree.com">首頁</a> <a href="http://hovertree.com/texiao/">特效</a> <a href="http://hovertree.com/menu/jquery/">jQuery</a>
<br />雙擊退出遮罩層
</div>
<div style="width:738px;height:186px;margin:10px auto;">
</div>
<div style="background-color:Green; width:100%;height:150px;"><h3>jquery彈出遮罩層</h3>
hovertree.com
</div>
<div style="background-color:Red; width:100%;height:150px;">歡迎</div>
<div style="background-color:Yellow; width:100%;height:150px;"><a href="http://hovertree.com/">首頁</a></div>
<div style="background-color:Silver; width:100%;height:150px;">何問起</div>
<div style="background-color:Aqua; width:1336px;height:150px;">hovertree.com</div>
<div style="background-color:Fuchsia; width:100%;height:150px;"><a href="http://hovertree.com/texiao/">更多特效</a></div>
<div style="background-color:Green; width:100%;height:150px;">hovertreetofoot</div>
<div style="background-color:Blue; width:100%;height:150px;"></div>
<div style="background-color:Olive; width:100%;height:350px;">何問起 返回頂部</div>
<div style="background-color:Green; width:100%;height:150px;">HoverTree</div>
<div style="background-color:Purple; width:100%;height:150px;">jquery</div>
<div style="background-color:Green; width:100%;height:150px;"><a href="http://hovertree.com/hvtart/bjae/65358656.htm" target="_blank">原文</a></div>
<div style="background-color:Lime; width:100%;height:150px;">hovertree.com</div>
<div style="background-color:Orange; width:100%;height:150px;">完整代碼</div>
<div style="height:130px;"></div>
<script type="text/javascript">
function ZZhovertree()
{
if ($("#zzhovertree").length==0) {
$('<div id="zzhovertree"></div>').appendTo($("body"));
$('#zzhovertree').on("dblclick", function () { $("#zzhovertree").hide() })
}
$('#zzhovertree').css({ "display": "", "position": "fixed", "left": "0px", "top": "0px", "background": "#000", "z-index": "1001", "-moz-opacity": "0.5", "opacity": ".50", "filter": "alpha(opacity=50)", "width": "100%", "height": "100%" }).show();
}
</script>

</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved