DIV CSS 佈局教程網

jQuery 遮罩層登錄對話框:可拖曳的彈出視窗
編輯:JQuery特效代碼     

效果體驗:https://hovertree.com/texiao/jquery/14.htm

另一個 Demo:https://hovertree.com/hvtart/bjae/jftxwtko.htm
Demo 3:https://hovertree.com/hvtart/bjae/dw0f8ytk.htm

這個版本用半透明遮罩覆蓋全頁,中間浮出登錄視窗,而且視窗可以用滑鼠拖曳(透過 easydrag 外掛)。視覺焦點集中、也不會誤觸背景內容,是電商與社群網站常見的做法。

互動程式碼

$(document).ready(function(){
    $('.one').click(function(){ $('.box2').show(); });      // 點擊登錄鈕,顯示遮罩層
    $('.login5 a').click(function(){ $('.box2').hide(); }); // 點擊關閉鈕,隱藏遮罩層
    $('.box').easydrag();                                   // 讓彈出視窗可拖曳
});

遮罩層的關鍵樣式

.box2 {
    width: 100%;
    height: 100%;
    margin: 0 auto;
    display: none;
    z-index: 5;
    position: fixed;
    background: rgba(0, 0, 0, 0.52) none repeat scroll 0% 0%;
    opacity: 1;
}

用 position:fixed 搭配 width/height:100% 就能完整覆蓋視窗,且捲動頁面時不會跟著跑;rgba(0,0,0,0.52) 直接定義半透明黑,比傳統 opacity 更乾淨——因為 opacity 會連子元素一起變透明,而 rgba 只影響背景色。z-index 則決定層級高低。

視窗內容版面

彈窗上半部 .login5 是標題列,右上方 a.close 用背景圖做出關閉鈕;下半部 .login51 分左右兩欄:.login5left 放帳號、密碼與登錄鈕,.login5right 以左側分隔線隔開,提供手機短信登錄、快速註冊與第三方帳號登入入口。左右兩欄都用 float 浮動,寬度相加剛好等於容器寬度。

完整程式碼

<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>彈出遮罩層登錄對話框 - 何問起</title>
 <script type="text/javascript" src="https://hovertree.com/texiao/jquery/14/jquery.easydrag.handler.beta2.js"></script>
 <script type="text/javascript" src="https://hovertree.com/ziyuan/jquery/jquery-1.11.3.min.js"></script>
 <script type="text/javascript">
$(document).ready(function(){
$('.one').click(function(){ $('.box2').show(); });
$('.login5 a').click(function(){ $('.box2').hide(); });
$('.box').easydrag();
});
 </script>
 <style type="text/css">
* { padding: 0px; margin: 0px; }
a { text-decoration: none; }
ul { list-style-type: none; }
.box { float: left; position:fixed; padding: 1px; top: 0px; z-index: 100; }
.box2 {
 width: 100%; height: 100%; margin: 0 auto; display: none;
 z-index: 5; position: fixed;
 background: rgba(0, 0, 0, 0.52) none repeat scroll 0% 0%;
 opacity: 1;
}
.login5 {
 width: 680px; height: 65px; background: #b52200; text-align: center;
 position: relative; margin: 150px auto 0px auto;
}
.login5 h2 { font-size: 30px; line-height: 65px; color: #ffffff; }
.login5 a {
 background: url(https://hovertree.com/texiao/jquery/14/loginhovertree.png) 0px 0px no-repeat;
 position: absolute; width: 16px; height: 16px; right: 10px; top: 25px;
}
.login51 { width: 600px; padding: 40px 40px 50px; margin: 0 auto; background: #EFEFEF; height: 300px; }
.login5left { float: left; width: 300px; height: 200px; font-size: 13px; }
.login5left1 { width: 100%; margin-bottom: 22px; float: left; position: relative; display: block; }
.login5left1 input {
 text-indent: 10px; width: 296px; color: #999; font-size: 13px;
 height: 40px; line-height: 40px; border: 1px solid #999; border-radius: 5px;
}
.login5left2 { height: 45px; line-height: 45px; width: 100%; margin-bottom: 22px; float: left; position: relative; display: block; }
.login5left2 .dl {
 float: left; width: 97px; height: 45px; line-height: 45px; text-align: center;
 background: #55ACEF; color: #fff; border-radius: 5px; display: inline-block;
 font-size: 14px; outline: medium none;
}
.login5left2 .wjmm { color: #55ACEF; margin-left: 20px; }
.login5right {
 float: left; margin-left: 35px; width: 220px; height: 280px;
 border-left: 1px solid #CBCBCB; padding-left: 35px;
}
.login5right1 {
 height: 40px; line-height: 40px; border-radius: 5px; border: 1px solid #55ACEF;
 width: 100%; margin-bottom: 22px; float: left; position: relative;
}
.login5right1 .sjdl {
 background: url(https://hovertree.com/texiao/jquery/14/hvtsmallico.png) no-repeat 30px 4px;
 height: 22px; line-height: 20px; padding-left: 60px; display: inline-block;
 color: #55ACEF; position: relative; margin-top: 10px;
}
.login5right2 { width: 100%; float: left; margin-bottom: 22px; position: relative; font-size: 13px; text-align: center; }
.login5right2 .zcdl { color: #55ACEF; font-size: 14px; }
.login5right3 { text-align: center; height: 40px; line-height: 40px; width: 100%; float: left; margin-bottom: 22px; position: relative; display: inline-block; font-size: 13px; }
.login5right3 b { height: 4px; border-top: 1px solid rgb(203, 203, 203); display: inline-block; width: 60px; }
.login5right3 .found { margin-left: 8px; }
.login5right3 .back { margin-right: 8px; }
.login5right4 { text-align: center; width: 100%; float: left; margin-bottom: 22px; position: relative; display: block; }
.login5right4 a { background: url(https://hovertree.com/texiao/jquery/14/hovertreeshare.png) no-repeat; width: 46px; height: 46px; position: absolute; }
.login5right4 .wb { background-position: 0px -47px; margin-left: -60px; }
.login5right4 .qq { background-position: 0px 0px; }
.one { padding:15px }
a { color:blue }
.centerhovertree { width:768px; margin:10px auto; text-align:center; }
 </style>
</head>
<body>
 <div class="centerhovertree">
 <h2>彈出遮罩層登錄對話框</h2>
 <input type="button" class="one" value="點擊這裡登錄" />
 </div>
 <div class="box">
 <div class="box2">
 <div class="login5">
 <h2>登錄</h2>
 <a class="close"></a>
 </div>
 <div class="login51">
 <form name="login5form" action="">
 <div class="login5left">
 <div class="login5left1"><input type="text" name="usernamehovertree" placeholder="用戶名/手機號/郵箱" /></div>
 <div class="login5left1"><input type="password" name="user_posswordhovertree" placeholder="密碼" /></div>
 <div class="login5left2">
 <a class="dl" href="#">登錄</a>
 <a class="wjmm" href="#">忘記密碼</a>
 </div>
 </div>
 <div class="login5right">
 <div class="login5right1"><a class="sjdl" href="#">手機短信登錄</a></div>
 <div class="login5right2">沒有賬號?<a class="zcdl" href="#">快速注冊</a></div>
 <div class="login5right3"><b class="found"></b>合作賬號登錄<b class="back"></b></div>
 <div class="login5right4"><a class="wb"></a><a class="qq"></a></div>
 </div>
 </form>
 </div>
 </div>
 </div>
</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved