欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

純js實(shí)現(xiàn)遮罩層效果原理分析

 更新時(shí)間:2014年05月27日 08:53:37   作者:  
這篇文章主要介紹了純js實(shí)現(xiàn)遮罩層效果,下面就它的原理做下分析,感興趣的朋友可以參考下
可以說這個(gè)功能,在我理解了前面的“貪吃蛇”之后,實(shí)在是與剛開始想象的難度差了好多,當(dāng)然是這種方式有取巧之嫌,終歸是實(shí)現(xiàn)了功能,我們來進(jìn)行分析整理

1、實(shí)現(xiàn)原理

本片文章的 是實(shí)現(xiàn)原理如下:

* 實(shí)際上彈出層、遮罩層和原頁面顯示分別為三個(gè)不同的div

* 彈出層的層級(jí)在遮罩層之上,遮罩層的層級(jí)在原頁面顯示之上;

* 遮罩層有通明效果

* 遮罩層沒有實(shí)際意義,則無需在html部分就寫上,當(dāng)然寫上同樣可以實(shí)現(xiàn)

2、代碼實(shí)現(xiàn)

html語言如下:
復(fù)制代碼 代碼如下:

<html>

....

<body>

<center>

<div ><input type="button" value="go" onclick="show()"></div>

<div id="alert" style="display:none;">

<form>

登錄

<input type="text"><input type="password"><input type="submit" value="login">

</form>

</div>

</center>

</body>

</html>

javascript實(shí)現(xiàn)彈出層和遮罩層:
復(fù)制代碼 代碼如下:

<span style="font-size:12px;">function show(){
var alertPart=document.getElementById("alert");
alertPart.style.display="block";
alertPart.style.position = "absolute";
alertPart.style.top = "50%";
alertPart.style.left = "50%";
alertPart.style.marginTop = "-75px";
alertPart.style.marginLeft = "-150px";
alertPart.style.background="cyan";
alertPart.style.width="300px";
alertPart.style.height="200px";
alertPart.style.zIndex = "501";

var mybg = document.createElement("div");
mybg.setAttribute("id","mybg");
mybg.style.background = "#000";
mybg.style.width = "100%";
mybg.style.height = "100%";
mybg.style.position = "absolute";
mybg.style.top = "0";
mybg.style.left = "0";
mybg.style.zIndex = "500";
mybg.style.opacity = "0.3";
mybg.style.filter = "Alpha(opacity=30)";
document.body.appendChild(mybg);

document.body.style.overflow = "hidden";
}
</script></span>

這里用z-index來區(qū)分層級(jí),opacity和filter:alpha(opacity=)透明度,document.createElement("div")和document.body.appendChild()這些都是在之前出現(xiàn)過,應(yīng)用過的了,這樣我們就能實(shí)現(xiàn)了,其實(shí)當(dāng)原理明白了的那一刻,一切也就容易多了吧。

路漫漫而修遠(yuǎn)兮啊

相關(guān)文章

最新評(píng)論