jQuery實(shí)現(xiàn)可兼容IE6的遮罩功能詳解
本文實(shí)例講述了jQuery實(shí)現(xiàn)可兼容IE6的遮罩功能。分享給大家供大家參考,具體如下:
最精簡(jiǎn),最強(qiáng)大的 jQuery 遮罩層效果。
當(dāng)瀏覽器改變大小時(shí),遮罩層的大小會(huì)相應(yīng)地改變。
遮罩層上方的對(duì)話框可隨 scroll 的改變而改變,即對(duì)話框在瀏覽器居中顯示。
HTML 代碼
<div id="main"><a onclick="showBg();" href="#" rel="external nofollow" rel="external nofollow" >點(diǎn)擊這里看 jQuery 遮罩層效果.</a></div> <div id="fullbg"></div> <div id="dialog"> <p class="close"><a onclick="closeBg();" href="#" rel="external nofollow" rel="external nofollow" >關(guān)閉</a></p> 正在加載,請(qǐng)稍后... </div>
CSS 代碼
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
margin: 0;
}
#main {
height: 1800px;
padding-top: 90px;
text-align: center;
}
#fullbg {
background-color: Gray;
left: 0px;
opacity: 0.5;
position: absolute;
top: 0px;
z-index: 3;
filter: alpha(opacity=50); /* IE6 */
-moz-opacity: 0.5; /* Mozilla */
-khtml-opacity: 0.5; /* Safari */
}
#dialog {
background-color: #FFF;
border: 1px solid #888;
display: none;
height: 200px;
left: 50%;
margin: -100px 0 0 -100px;
padding: 12px;
position: fixed !important; /* 浮動(dòng)對(duì)話框 */
position: absolute;
top: 50%;
width: 200px;
z-index: 5;
}
#dialog p {
margin: 0 0 12px;
}
#dialog p.close {
text-align: right;
}
jquery 代碼
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
//顯示灰色 jQuery 遮罩層
function showBg() {
var bh = $("body").height();
var bw = $("body").width();
$("#fullbg").css({
height:bh,
width:bw,
display:"block"
});
$("#dialog").show();
}
//關(guān)閉灰色 jQuery 遮罩
function closeBg() {
$("#fullbg,#dialog").hide();
}
</script>
<!--[if lte IE 6]>
<script type="text/javascript">
// 浮動(dòng)對(duì)話框
$(document).ready(function() {
var domThis = $('#dialog')[0];
var wh = $(window).height() / 2;
$("body").css({
"background-image": "url(about:blank)",
"background-attachment": "fixed"
});
domThis.style.setExpression('top', 'eval((document.documentElement).scrollTop + ' + wh + ') + "px"');
});
</script>
<![endif]-->
這里別忘記引入jquery文件
更多關(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動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery實(shí)現(xiàn)簡(jiǎn)單網(wǎng)頁(yè)遮罩層/彈出層效果兼容IE6、IE7
- 兼容主流瀏覽器的jQuery+CSS 實(shí)現(xiàn)遮罩層的簡(jiǎn)單代碼
- JS遮罩層效果 兼容ie firefox jQuery遮罩層
- jQuery+css+html實(shí)現(xiàn)頁(yè)面遮罩彈出框
- JQuery 遮罩層實(shí)現(xiàn)(mask)實(shí)現(xiàn)代碼
- jQuery+html5實(shí)現(xiàn)div彈出層并遮罩背景
- jquery彈出關(guān)閉遮罩層實(shí)例
- jQuery操作dom實(shí)現(xiàn)彈出頁(yè)面遮罩層(web端和移動(dòng)端阻止遮罩層的滑動(dòng))
- jquery 圓角遮罩圖片實(shí)現(xiàn)圖片圓角
- jQuery+AJAX實(shí)現(xiàn)遮罩層登錄驗(yàn)證界面(附源碼)
- jquery下實(shí)現(xiàn)overlay遮罩層代碼
相關(guān)文章
jQuery簡(jiǎn)易時(shí)光軸實(shí)現(xiàn)方法示例
這篇文章主要介紹了jQuery簡(jiǎn)易時(shí)光軸實(shí)現(xiàn)方法,可實(shí)現(xiàn)點(diǎn)擊底部鏈接動(dòng)態(tài)加載內(nèi)容的功能,涉及jQuery響應(yīng)鼠標(biāo)事件動(dòng)態(tài)操作頁(yè)面元素屬性的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-03-03
jquery pagination插件實(shí)現(xiàn)無(wú)刷新分頁(yè)代碼
首先,我們要準(zhǔn)備的文件有jquery.js,jquery.pagination.js,pagination.css,還有一個(gè)就是經(jīng)常用的table布局的css文件。這些文件都會(huì)在后面的文件中包含。2009-10-10
jQuery表單校驗(yàn)插件validator使用方法詳解
這篇文章主要為大家詳細(xì)介紹了jQuery表單校驗(yàn)插件validator的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02
jQuery css() 方法動(dòng)態(tài)修改CSS屬性
在jquery中我們要?jiǎng)討B(tài)的修改css屬性我們只要使用css()方法就可以實(shí)現(xiàn)了,下面我來(lái)給各位同學(xué)詳細(xì)介紹介紹。2016-09-09
jQuery中noconflict函數(shù)的實(shí)現(xiàn)原理分解
這篇文章主要介紹了jQuery中noconflict函數(shù)的實(shí)現(xiàn)原理分解,noconflict是用來(lái)防止變量沖突的,本文就分解了它的實(shí)現(xiàn)原理,并分析了它的實(shí)現(xiàn)源碼,需要的朋友可以參考下2015-02-02
jQuery產(chǎn)品間斷向下滾動(dòng)效果核心代碼
這篇文章主要為大家分享了jQuery產(chǎn)品間斷向下滾動(dòng)的核心代碼,需要的朋友可以參考下2014-05-05
40個(gè)有創(chuàng)意的jQuery圖片、內(nèi)容滑動(dòng)及彈出插件收藏集之一
在網(wǎng)頁(yè)的首頁(yè)或圖片專題頁(yè)面很多地方都會(huì)用到圖片滑動(dòng)插件來(lái)循環(huán)切換多張圖片,并且用戶可以點(diǎn)擊左右按鈕來(lái)切換圖片。相信大家都知道jQuery是最優(yōu)秀的Javascript框架之一2011-12-12

