原生JS可拖動(dòng)彈窗效果實(shí)例代碼
這個(gè)代碼不是我原創(chuàng)的,只是最近想學(xué)自己做一個(gè)很漂亮的彈窗,自己本來是不會(huì)怎么寫的,所以上網(wǎng)去找了下,感覺這個(gè)不錯(cuò),很簡(jiǎn)單,很實(shí)用,入門很棒。我就改了下,使邏輯性和可讀性更好。
原作者已不可考。感謝原作者,阿門。
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"/>
<meta name="author" content="www.newxing.com" />
<meta name="author email" content="123@linhaibo.com" />
<title>彈出窗口登錄效果</title>
<style>
body,#Mdown {
margin: 0;
padding: 0;
text-align: center;
font: normal 14px/180% Tahoma,sans-serif;
}
#loginBox {
margin: 0 auto;
padding: 0px;
text-align: left;
width: 280px;
height: 150px;
background: #EAEEFF;
font-size: 9pt;
border: 1px solid #829AFF;
overflow: hidden;
filter: alpha(opacity=90);
opacity: 1;
}
#loginBox .title {
text-align: left;
padding-left: 10px;
font-size: 11pt;
border-bottom: 1px solid #829AFF;
height: 25px;
line-height: 25px;
cursor: move;
}
#loginBox .t1 {
float: left;
font-weight: bold;
color: #AA7B7B;
text-decoration: none;
}
#loginBox .t2 {
float: right;
text-align: center;
line-height: 18px;
height: 18px;
width: 18px;
margin-top: 3px;
margin-right: 2px;
overflow: hidden;
border: 1px solid #FF5889;
background: #FFE0E9;
cursor: pointer;
}
#loginBox .login {
text-align: center;
width: 100%;
height: 100%;
}
input.submit {
float: right;
border: 1px solid #829AFF;
FONT-SIZE: 9px;
background: #EAEEFF;
HEIGHT: 20px;
margin-top: 5px;
margin-right: 70px;
}
#bgDiv {
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
right: 0px;
background-color: #777;
opacity: 0.7;
}
</style>
</head>
<body>
<div id="bgDiv" style="display:none;">
</div>
<a href="javascript:" onClick="bgDiv.style.display='';loginBox.style.display='';">登錄</a>
<div id="loginBox" style="position:absolute; left:367px; top:150px; z-index:1;display: none;" >
<div class="title" id="Mdown">
<span class="t1">登錄</span>
<span class="t2" title="關(guān)閉" onClick="login.style.display='none';bgDiv.style.display='none'">X</span>
</div>
<div class="login">
<form method="post" action="#">
<table>
<tr>
<td>用戶名:</td><td><input type="text"name="username" size="12" maxlength="10"></td>
</tr>
<tr>
<td>密 碼:</td><td><input type="text"name="password" size="12" maxlength="10"></td>
</tr>
<tr>
<td></td><td><button class="submit" type="submit">登陸</button></td>
</tr>
</table>
</form>
</div>
</div>
<script type="text/javascript">
var IsMousedown, LEFT, TOP, login;
document.getElementById("Mdown").onmousedown=function(e) {
login = document.getElementById("loginBox");
IsMousedown = true;
e = e||event;
LEFT = e.clientX - parseInt(login.style.left);
TOP = e.clientY - parseInt(login.style.top);
document.onmousemove = function(e) {
e = e||event;
if (IsMousedown) {
login.style.left = e.clientX - LEFT + "px";
login.style.top = e.clientY - TOP + "px";
}
}
document.onmouseup=function(){
IsMousedown=false;
}
}
</SCRIPT>
</body>
</html>
相關(guān)文章
在JavaScript中使用揭示模式創(chuàng)建對(duì)象的示例
揭示模式是一種在JavaScript中創(chuàng)建對(duì)象的方法,通過返回一個(gè)包含公開屬性和方法的對(duì)象,可以控制哪些部分可以被外部訪問,從而實(shí)現(xiàn)更好的封裝和安全性,感興趣的朋友一起看看吧2024-12-12bootstrap中selectpicker下拉框使用方法實(shí)例
這篇文章主要給大家介紹了關(guān)于bootstrap中selectpicker下拉框使用的相關(guān)資料,文中通過示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03利用js+css+html實(shí)現(xiàn)固定table的列頭不動(dòng)
本文分享了利用js+css+html實(shí)現(xiàn)固定table的列頭不動(dòng)的實(shí)例代碼。小編認(rèn)為具有很好的參考價(jià)值,感興趣的朋友可以看下2016-12-12JS中‘hello’與new String(‘hello’)引出的問題詳解
這篇文章主要給大家介紹了關(guān)于JS中'hello'與new String('hello')引出的問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08基于JavaScript實(shí)現(xiàn)鼠標(biāo)箭頭移動(dòng)圖片跟著移動(dòng)
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)鼠標(biāo)箭頭移動(dòng)圖片跟著移動(dòng)的核心代碼,代碼比較簡(jiǎn)單易懂,需要的朋友可以參考下2016-08-08JavaScript實(shí)現(xiàn)短信倒計(jì)時(shí)60s
本文給大家分享一段實(shí)例代碼給大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)短信倒計(jì)時(shí)60s功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2017-10-10解析JavaScript中的不可見數(shù)據(jù)類型
這篇文章主要是對(duì)JavaScript中的不可見數(shù)據(jù)類型進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-12-12