Наверх
РегистрацияВход на сайтВход на сайт
  • Страница 1 из 1
  • 1
ФайлоДром Форум » Web-мастеру и разработчику » Скрипты для uCoz » Модальное окно на jQuery
Модальное окно на jQuery
Bars90 Дата: Ср, 27 Июл 2011, 12:05 | Сообщение # 1
Суперактивный
Сообщений: 312
Дополнительные сведения »
Offline


1. CSS
Code
a {color: #333; text-decoration: none; font-size: 25px;}  
a:hover {color:#ccc; text-decoration:none}  
#mask {  
   position:absolute;  
   left:0;  
   top:0;  
   z-index:9000;  
   background-color:#000;  
   display:none;  
   font-family: Georgia;  
   }  
#boxes .window {  
   position:absolute;  
   left:0;  
   top:0;  
   width:440px;  
   height:200px;  
   display:none;  
   z-index:9999;  
   padding:20px;  
   text-align: center;  
   font-size: 25px;  
   }  
#boxes #dialog {  
   width:375px;  
   height:203px;  
   padding:10px;  
   background-color:#ffffff;  
   }  
.close {  
   float: right;  
   margin-top: 148px;  
   }

2. Подключение jQuery
Code
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>


Данный код добавляем в раздел <head>
3.
Code
JavaScript  
<script type="text/javascript">  
$(document).ready(function() {  
   //select all the a tag with name equal to modal  
   $('a[name=modal]').click(function(e) {  
   //Cancel the link behavior  
   e.preventDefault();  
   //Get the A tag  
   var id = $(this).attr('href');  
   //Get the screen height and width  
   var maskHeight = $(document).height();  
   var maskWidth = $(window).width();  
   //Set heigth and width to mask to fill up the whole screen  
   $('#mask').css({'width':maskWidth,'height':maskHeight});  
   //transition effect  
   $('#mask').fadeIn(1000);  
   $('#mask').fadeTo("slow",0.8);  
   //Get the window height and width  
   var winH = $(window).height();  
   var winW = $(window).width();  
   //Set the popup window to center  
   $(id).css('top', winH/2-$(id).height()/2);  
   $(id).css('left', winW/2-$(id).width()/2);  
   //transition effect  
   $(id).fadeIn(2000);  
   });  
   //if close button is clicked  
   $('.window .close').click(function (e) {  
   //Cancel the link behavior  
   e.preventDefault();  
   $('#mask, .window').hide();  
   });  
   //if mask is clicked  
   $('#mask').click(function () {  
   $(this).hide();  
   $('.window').hide();  
   });  
});  
</script>


Данный код, также, добавляем в раздел <head>, но после кода подключения jQuery.
4. HTML
Code
<a href="#dialog" name="modal">Простое модальное окно</a>  
<div id="boxes">  
   <div id="dialog" class="window">  
   Простое модальное окно <br>  
   <span><a href="#" class="close"/>Закрыть его</a>  
   </div>  
   <div id="mask"></div>  
</div>

 
ФайлоДром Форум » Web-мастеру и разработчику » Скрипты для uCoz » Модальное окно на jQuery
  • Страница 1 из 1
  • 1
Поиск: