create a simple popup box
Today i will show you how to create a simple popup box with close button, no need 3th-party plugins, just one file html and jquery library.
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset='utf-8'/>
- <title>jQuery Popup Box Demo</title>
- <script src="jquery-1.9.0.min.js"></script>
- <script>
- $(document).ready(function(){
- $('h1').click(function(){ //you click into h1
- $('.hiddenbox').fadeIn(); //show popup box
- $('div:not(".hiddenbox")').hide(); //hide all elements except class hiddenbox
- $('.hiddenbox').appendTo('body'); //set class hiddenbox display as body
- })
- $('span.close').click(function(){ //you click close button
- $('.hiddenbox').fadeOut(); //close popup box
- $('body').appendTo('body'); // set body as body
- $('div:not(".hiddenbox")').show(); //show hidden elements
- });
- });
- </script>
- <style>
- .wrapper{width:100%;height:100%;background:rgba(38,35,35,0.5);}
- .hiddenbox{width:300px;height:300px;background:#000;margin:0 auto;overflow:hidden;display:none;opacity:none;} /*display:none is important part*/
- .close{width:10px;height:10px;background:red;cursor:pointer}
- h1{cursor:pointer}
- </style>
- </head>
- <body>
- <div class="wrapper" style="">
- <h1>click here to show Popup</h1>
- <div class="hiddenbox">
- <span class="close">close</span>
- </div>
- </div>
- </body>
- </html>
I got 99 problems but a bitch ain't one