JavaScript編寫頁面半透明遮罩效果的簡單示例
半透明遮罩層效果基本上都是使用插件實(shí)現(xiàn)的,下面為大家分享下使用原生js實(shí)現(xiàn)半透明遮罩效果,感興趣的朋友可以參考下哈,希望對你熟悉原生js有所幫助
<div >
<h4><span>現(xiàn)在注冊</span><span >關(guān)閉</span></h4>
<p>
<label> 用戶名</label>
<input type="text" class="myinp" onmouseover="this.style.border='1px solid #f60'" onfoucs="this.style.border='1px solid #f60'" onblur="this.style.border='1px solid #ccc'" />
</p>
<p>
<label> 密 碼</label>
<input type="password" class="myinp" onmouseover="this.style.border='1px solid #f60'" onfoucs="this.style.border='1px solid #f60'" onblur="this.style.border='1px solid #ccc'" />
</p>
<p>
<input type="submit" value="注冊" class="sub" />
<input type="reset" value="重置" class="sub" />
</p>
</div>
<div ></div><!-- 遮罩層div-->
<script type="text/javascript">
var myAlert = document.getElementById("alert");
var myMask=document.getElementById('mask');
var reg = document.getElementById("content").getElementsByTagName("a")[0];
var mClose = document.getElementById("close");
reg.onclick = function()
{
myMask.style.display="block";
myAlert.style.display = "block";
myAlert.style.position = "absolute";
myAlert.style.top = "50%";
myAlert.style.left = "50%";
myAlert.style.marginTop = "-75px";
myAlert.style.marginLeft = "-150px";
document.body.style.overflow = "hidden";
}
mClose.onclick = function()
{
myAlert.style.display = "none";
myMask.style.display = "none";
}
</script>
</body>
</html>
全屏幕遮蓋
<!DOCTYPE html>
<style>
#mask {
position:fixed;width:100%;
top:0px;left:0px;
_position:absolute;
_top:expression(documentElement.scrollTop);
background:rgba(0,0,0,0.5);
background:transparent\9;
filter:progid:DXImageTransform.Microsoft.Gradient(
startColorStr=#80000000,endColorStr=#80000000
);
display:none;
}
#mask_td {text-align:center;}
</style>
<img
src="http://web-tinker.com/images/TheMagicConch.jpg"
width="100" id="img"
/>
<table id="mask"><tr><td id="mask_td"></td></tr></table>
<script>
//判斷瀏覽器
var isIE=navigator.userAgent.match(/MSIE (\d)/i);
isIE=isIE?isIE[1]:isIE;
//聲明變量
var img,mask;
//獲取元素
img=document.getElementById("img");
mask=document.getElementById("mask");
mask.td=document.getElementById("mask_td");
//計(jì)算mask的大小
mask.setSize=function(){
//獲取文檔可見區(qū)域?qū)挾炔⒃O(shè)置到mask上
var de=document.documentElement;
mask.style.width=de.clientWidth+"px"
mask.style.height=de.clientHeight+"px";
};
//添加show方法
mask.show=function(){
//隱藏頁面的滾動(dòng)條
document[
isIE<9?"documentElement":"body"
].style.overflow="hidden";
//計(jì)算mask的大小
mask.setSize();
//顯示
mask.style.display=isIE==6?"block":"table";
};
//添加hide方法
mask.hide=function(){
//顯示頁面滾動(dòng)條
document[
isIE<9?"documentElement":"body"
].style.overflow="";
//清空里面的內(nèi)容
mask.td.innerHTML="";
//隱藏
mask.style.display="none";
};
//添加append方法
mask.append=function(e){
//在mask的TD里面添加內(nèi)容哦你
mask.td.appendChild(e);
};
//點(diǎn)擊mask關(guān)閉
mask.onclick=function(e){
//判斷事件來源,如果是空白區(qū)域被點(diǎn)擊了就關(guān)閉mask
e=e||event;
(e.target||e.srcElement)==mask.td&&mask.hide();
};
//窗體大小改變時(shí)也改變mask的大小
window.onresize=function(){
mask.setSize();
};
//點(diǎn)擊圖片的事件
img.onclick=function(){
//創(chuàng)建一個(gè)圖片對象
var o=new Image;
//設(shè)置圖片的地址
o.src=img.src;
//在mask內(nèi)添加內(nèi)容
mask.append(o);
//顯示mask
mask.show();
};
</script>
- js實(shí)現(xiàn)鼠標(biāo)移動(dòng)到圖片產(chǎn)生遮罩效果
- js+html5實(shí)現(xiàn)半透明遮罩層彈框效果
- js遮罩效果制作彈出注冊界面效果
- JavaScript仿flash遮罩動(dòng)畫效果
- 使用CSS+JavaScript或純js實(shí)現(xiàn)半透明遮罩效果的實(shí)例分享
- 基于JavaScript實(shí)現(xiàn)全屏透明遮罩div層鎖屏效果
- js點(diǎn)擊按鈕實(shí)現(xiàn)帶遮罩層的彈出視頻效果
- js彈窗返回值詳解(window.open方式)
- js彈出框、對話框、提示框、彈窗實(shí)現(xiàn)方法總結(jié)(推薦)
- JS使用遮罩實(shí)現(xiàn)點(diǎn)擊某區(qū)域以外時(shí)彈窗的彈出與關(guān)閉功能示例
相關(guān)文章
Firefox中autocomplete="off" 設(shè)置不起作用Bug的解決方法
在實(shí)現(xiàn)補(bǔ)全提示功能時(shí)(Suggest),都會(huì)給輸入框(Input)元素添加autocomplete屬性,且值設(shè)為off。2011-03-03
一文詳解為什么JavaScript中的JSON.parse()報(bào)錯(cuò)
這篇文章主要介紹了JavaScript中JSON.parse()方法的使用和常見錯(cuò)誤,包括非法JSON格式、包含不可解析的字符、使用單引號(hào)等,并提供了相應(yīng)的解決方案和實(shí)際項(xiàng)目中的代碼示例,需要的朋友可以參考下2025-03-03
wangEditor編輯器失去焦點(diǎn)后仍然可以在原位置插入圖片分析
本文給大家?guī)淼氖且豢罘浅2诲e(cuò)的富文本編輯器WangEditor,他最大的特點(diǎn)是它在ie6,7,8上都可以做到失去焦點(diǎn)后仍然可以在原位置插入圖片,而且代碼量很少,下面我們就來分析下他是如何實(shí)現(xiàn)的呢2015-05-05
當(dāng)json鍵為數(shù)字時(shí)的取值方法解析
對于數(shù)字鍵名或者非正常變量字符(比如有空格),必須使用 aa[x]的方式2013-11-11
JavaScript Array.flat()函數(shù)用法解析
這篇文章主要介紹了JavaScript Array.flat()函數(shù)用法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09
js彈出層永遠(yuǎn)居中實(shí)現(xiàn)思路及代碼
彈出層永遠(yuǎn)居中的方法有很多,在本文為大家詳細(xì)介紹下使用js是如何輕松實(shí)現(xiàn)的,喜歡的朋友可以參考下2013-11-11
讓插入到 innerHTML 中的 script 跑起來的代碼
讓插入到 innerHTML 中的 script 跑起來的代碼...2007-11-11

