create a simple popup box

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.
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'/>
  5. <title>jQuery Popup Box Demo</title>
  6. <script src="jquery-1.9.0.min.js"></script>
  7. <script>
  8. $(document).ready(function(){
  9. $('h1').click(function(){ //you click into h1
  10. $('.hiddenbox').fadeIn(); //show popup box
  11. $('div:not(".hiddenbox")').hide(); //hide all elements except class hiddenbox
  12. $('.hiddenbox').appendTo('body'); //set class hiddenbox display as body
  13. })
  14. $('span.close').click(function(){ //you click close button
  15. $('.hiddenbox').fadeOut(); //close popup box
  16. $('body').appendTo('body');  // set body as body
  17. $('div:not(".hiddenbox")').show();  //show hidden elements
  18. });
  19. });
  20. </script>
  21. <style>
  22. .wrapper{width:100%;height:100%;background:rgba(38,35,35,0.5);}
  23. .hiddenbox{width:300px;height:300px;background:#000;margin:0 auto;overflow:hidden;display:none;opacity:none;} /*display:none is important part*/
  24. .close{width:10px;height:10px;background:red;cursor:pointer}
  25. h1{cursor:pointer}
  26. </style>
  27. </head>
  28. <body>
  29. <div class="wrapper" style="">
  30. <h1>click here to show Popup</h1>
  31. <div class="hiddenbox">
  32. <span class="close">close</span>
  33. </div>
  34. </div>
  35. </body>
  36. </html>


I got 99 problems but a bitch ain't one