Advertisement
kotvalera83

Jquery Всплывающее окно с затемнением фона

Jan 31st, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.23 KB | None | 0 0
  1. <!doctipe html/>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  6. <script>
  7.  
  8. function open_pop_up(box) {
  9.     $("#overlay").show();
  10.     $(box).center_pop_up();
  11.     $(box).show(500);
  12. }
  13.  
  14. function close_pop_up(box) {
  15.     $(box).hide(500);
  16.     $("#overlay").delay(550).hide(1);
  17. }
  18.  
  19. $(document).ready(function(){
  20.  
  21.     jQuery.fn.center_pop_up = function(){
  22.         this.css('position','absolute');  
  23.         this.css('top', ($(window).height() - this.height()) / 2+$(window).scrollTop() + 'px');  
  24.         this.css('left', ($(window).width() - this.width()) / 2+$(window).scrollLeft() + 'px');
  25.     }
  26.  
  27. });
  28. </script>
  29.  
  30. <style>
  31. #overlay {
  32.   position: absolute;
  33.   top: 0px;
  34.   left: 0px;
  35.   background: #000;
  36.   opacity: 0.7;
  37.   z-index: 9000;
  38.   width: 100%;
  39.   height: 100%;
  40.   display: none;
  41. }
  42.  
  43. #pop-up {
  44.   width: 500px;
  45.   height: 200px;
  46.   border: 1px solid #e8e8e8;
  47.   background: #fdfdfd;
  48.   display: none;
  49.   z-index: 9001;
  50. }
  51.  
  52. span, p {
  53.   cursor: pointer;
  54. }
  55. </style>
  56. </head>
  57. <body>
  58.     <span onclick="open_pop_up('#pop-up');">Открыть</span>
  59.     <div id="pop-up">
  60.         <p onclick="close_pop_up('#pop-up');">Закрыть</p>
  61.     </div>
  62.     <div id="overlay"></div>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement