本文實(shí)例為大家分享了JSP實(shí)現(xiàn)彈出登陸框以及陰影效果的具體代碼,供大家參考,具體內(nèi)容如下
先說下思想JSP彈出登陸框的思想,我們在JSP中新建一個div層,然后Display設(shè)置成none,這樣打開后是不可見的,然后我們通過一個點(diǎn)擊事件,比如當(dāng)我們點(diǎn)擊登陸按鈕時,就給它注冊一個點(diǎn)擊事件,使得div層變得可見,這樣就實(shí)現(xiàn)了彈出效果。
代碼如下:
CSS樣式:
style>
.win {
POSITION:absolute; left:55%; top:60%;
width:400px; height:250px;
margin-left:-300px;margin-top:-200px; border:1px solid #888;
background-color: #d6cfcb; text-align: center;
line-height: 60px; z-Index:3;
}
/style>
JS代碼:
script>
function openLogin(){
document.getElementById("win").style.display="";
}
function closeLogin(){
document.getElementById("win").style.display="none";
}
/script>
html代碼:
div id="win" class="win" style="display:none">
form action="javascript:jump();" method="post">
span style="font-size: 20px;"> 歡迎登陸網(wǎng)上書店 /span> br />
label class="label"> 用戶名: /label> input type="text" class="input" id="user" /> br />
label class="label"> 密碼: /label> input type="password" class="input" id="psw" /> br />
input type="reset" value="重輸" class="input1" />
input type="button" value="退出" class="input3" onclick="closeLogin();" />
input type="submit" value="確定" class="input2" />
/form>
/div>
a href="javascript:openLogin();" >打開/a>
a href="javascript:closeLogin();" >關(guān)閉/a>
運(yùn)行的效果:
![](/d/20211017/a73903bf724e9df22e690b8e029a13e6.gif)
點(diǎn)擊打開按鈕:
![](/d/20211017/75b844bb89a253ab6c291540d5c9dc6a.gif)
點(diǎn)擊關(guān)閉就消失了。
再說下在點(diǎn)擊之后造成的陰影效果,即除了登錄框外的都會變暗,并且不可操作。核心思想就是我們在設(shè)置一個div層,并且將其初始設(shè)置為隱藏,當(dāng)點(diǎn)擊比如登陸時,和登陸框一起彈出,并且設(shè)置這個div的寬度和高度分別為屏幕的高度和寬度,顏色上也是選擇暗一點(diǎn)的帶有透明度的顏色(這個是在上面登錄框的基礎(chǔ)上進(jìn)行操作的)
代碼如下:
CSS樣式:
style>
.hidebg {
position:absolute; left:0px; top:0px;
background-color:#000;
width:100%;
filter:alpha(opacity=60);
opacity:0.6;
display:none;
z-Index:2;
}
/style>
JS代碼:
function openLogin(){
document.getElementById("hidebg").style.display="block";
document.getElementById("hidebg").style.height=document.body.clientHeight+"px";
}
function closeLogin(){
document.getElementById("hidebg").style.display="none";
}
html代碼:
div id="hidebg" class="hidebg">/div>
運(yùn)行的效果:
![](/d/20211017/9c4a6a33fcadaa38dc7b60e63cc3fd54.gif)
點(diǎn)擊打開:
![](/d/20211017/4cb0e12b98b80123eff3eae94fabd475.gif)
點(diǎn)擊關(guān)閉就可以關(guān)閉了。
上面的兩部分代碼可以和寫在一起構(gòu)成彈出登錄框以及周圍陰影的效果。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- WebGL three.js學(xué)習(xí)筆記之陰影與實(shí)現(xiàn)物體的動畫效果
- 利用Three.js如何實(shí)現(xiàn)陰影效果實(shí)例代碼
- js當(dāng)前頁面登錄注冊框,固定div,底層陰影的實(shí)例代碼
- JS當(dāng)前頁面登錄注冊框,固定DIV,底層陰影的實(shí)例代碼
- js 實(shí)現(xiàn)無干擾陰影效果 簡單好用(附文件下載)
- Div+Js實(shí)現(xiàn)的帶陰影菜單 微軟以前網(wǎng)站曾用過
- 用JS實(shí)現(xiàn)網(wǎng)頁元素陰影效果的研究總結(jié)
- JavaScript canvas實(shí)現(xiàn)帶有陰影的圖形和文字