Логин прозорец с jQuery
Автор: stoqnski
Здравейте в този урок ще ви покажа как да си направите логин прозорец от цъкане на линк с jQuery : http://mp3-store.freehostia.com/news-system/login
(1) Създаваме си нов документ с име „index.php“ и вкарваме следния код:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Логин прозорец с jQuery [by stoqnski]</title>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1251' />- тук няма нищо за обесняване … , но все пак ако има нещо неясно погледнете началните уроци за хтмл
(2) Вкарваме последната версия на jQuery в документа и скрипта , който ще изпълнява функцията :
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>
$(document).ready(function() {
$('a[name=modal]').click(function(e) {
e.preventDefault();
var id = $(this).attr('href');
var maskHeight = $(document).height();
var maskWidth = $(window).width();
$('#mask').css({'width':maskWidth,'height':maskHeight});
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);
var winH = $(window).height();
var winW = $(window).width();
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
$(id).fadeIn(2000);
});
$('.window .close').click(function (e) {
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
</script>Обяснение :
$(‘a[name=modal]’).click(function(e) {
- избираме всички „а“ тагове с име равно на “ modal“
e.preventDefault();
- показваме дефаут функция
var id = $(this).attr(‘href’);
- взимаме „а“ тага
var maskHeight = $(document).height();
var maskWidth = $(window).width();
- взимаме височината и ширината на екрана
$(‘#mask’).css({‘width’:maskWidth,’height’:maskHeight});
- след като са взети са ни необходими за „маскиране“ (затъмняване) на целия екран
$(‘#mask’).fadeIn(1000);
$(‘#mask’).fadeTo(„slow“,0.8);
- ефекта на прехода , урок за fadeIn ефекта потърсете в jquery.com
var winH = $(window).height();
var winW = $(window).width();
- взимаме височината и ширината на прозореца
$(id).css(‘top’, winH/2-$(id).height()/2);
$(id).css(‘left’, winW/2-$(id).width()/2);
- центрираме прозорчето
$(‘.window .close’).click(function (e) {
- ако изход бутона е кликнат
e.preventDefault();
$(‘#mask’).hide();
$(‘.window’).hide();
});
- скриваме прозореца
$(‘#mask’).click(function () {
$(this).hide();
$(‘.window’).hide();
});
- ако „маската“ е кликната
(3) Това беше по javascript-а сега вкарваме малко стил :
<style>
body {
font-family:verdana;
font-size:15px;
}
a {color:#333; text-decoration:none}
a:hover {color:#ccc; text-decoration:none}
#mask {
position:absolute;
left:0;
top:0;
z-index:9000;
background-color:#000;
display:none;
}
#boxes .window {
position:absolute;
left:0;
top:0;
width:440px;
height:200px;
display:none;
z-index:9999;
padding:20px;
}
#boxes #dialog {
width:375px;
height:203px;
padding:10px;
background-color:#ffffff;
}
#boxes #dialog1 {
width:375px;
height:203px;
}
#dialog1 .d-header {
background:url(images/login-header.png) no-repeat 0 0 transparent;
width:375px;
height:150px;
}
#dialog1 .d-header input {
position:relative;
top:60px;
left:100px;
border:2px solid #EB0873;
height:22px;
width:200px;
font-size:15px;
padding:5px;
margin-top:4px;
}
#dialog1 .d-blank {
float:left;
background:url(images/login-blank.png) no-repeat 0 0 transparent;
width:267px;
height:53px;
}
#dialog1 .d-login {
float:left;
width:108px;
height:53px;
}
</style>
</head>
(4) А сега хтмл кода :
<body>
<ul>
<li><a href="#dialog1" name="modal">Вход към админ панела -></a></li>
</ul>
<div id="boxes">
<div id="dialog1" class="window">
<div class="d-header">
<form action="index.php" >
<input type="text" value="Потребител" onclick="this.value=''"/><br/>
<input type="password" value="Парола" onclick="this.value=''"/>
</div>
<div class="d-blank"></div>
<div class="d-login">
<input type="image" alt="Login" title="Вход" src="images/login-button.png"/></form></div>
</div>
<div id="mask"></div>
</div>
</body>
</html>(5) Забележки:
#mask {
position:absolute;
left:0;
top:0;
z-index:9000;
background-color:#000;
display:none;
}
<div id="mask"></div>
</div>*служи за затъмняване на екрана – не го променяйте !
(6) Ето готовият index.php :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Логин прозорец с jQuery [ by stoqnski ] </title>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1251' />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>
$(document).ready(function() {
$('a[name=modal]').click(function(e) {
e.preventDefault();
var id = $(this).attr('href');
var maskHeight = $(document).height();
var maskWidth = $(window).width();
$('#mask').css({'width':maskWidth,'height':maskHeight});
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);
var winH = $(window).height();
var winW = $(window).width();
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
$(id).fadeIn(2000);
});
$('.window .close').click(function (e) {
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
</script>
<style>
body {
font-family:verdana;
font-size:15px;
}
a {color:#333; text-decoration:none}
a:hover {color:#ccc; text-decoration:none}
#mask {
position:absolute;
left:0;
top:0;
z-index:9000;
background-color:#000;
display:none;
}
#boxes .window {
position:absolute;
left:0;
top:0;
width:440px;
height:200px;
display:none;
z-index:9999;
padding:20px;
}
#boxes #dialog {
width:375px;
height:203px;
padding:10px;
background-color:#ffffff;
}
#boxes #dialog1 {
width:375px;
height:203px;
}
#dialog1 .d-header {
background:url(images/login-header.png) no-repeat 0 0 transparent;
width:375px;
height:150px;
}
#dialog1 .d-header input {
position:relative;
top:60px;
left:100px;
border:2px solid #EB0873;
height:22px;
width:200px;
font-size:15px;
padding:5px;
margin-top:4px;
}
#dialog1 .d-blank {
float:left;
background:url(images/login-blank.png) no-repeat 0 0 transparent;
width:267px;
height:53px;
}
#dialog1 .d-login {
float:left;
width:108px;
height:53px;
}
</style>
</head>
<body>
<ul>
<li><a href="#dialog1" name="modal">Вход към админ панела -></a></li>
</ul>
<div id="boxes">
<div id="dialog1" class="window">
<div class="d-header">
<form action="index.php" >
<input type="text" value="Потребител" onclick="this.value=''"/><br/>
<input type="password" value="Парола" onclick="this.value=''"/>
</div>
<div class="d-blank"></div>
<div class="d-login">
<input type="image" alt="Login" title="Вход" src="images/login-button.png"/></form></div>
</div>
<div id="mask"></div>
</div>
</body>
</html>Картинките поставете в папка „images“ :
http://mp3-store.freehostia.com/news-system/login/images/login-blank.png
http://mp3-store.freehostia.com/news-system/login/images/login-button.png
http://mp3-store.freehostia.com/news-system/login/images/login-header.png
Това беше урока.


