Advertisement
r_martins

Adicionando popup no Magento 2 (Popup generico HTML + JavaScript + CSS)

Sep 12th, 2022
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <!-- The Modal -->
  2. <div id="myModal" class="modal">
  3.  
  4. <!-- Modal content -->
  5. <div class="modal-content">
  6. <span class="close">&times;</span>
  7. <p>Some text in the Modal..</p>
  8. </div>
  9.  
  10. <style>
  11. /* The Modal (background) */
  12. .modal {
  13. display: none; /* Hidden by default */
  14. position: fixed; /* Stay in place */
  15. z-index: 1; /* Sit on top */
  16. left: 0;
  17. top: 0;
  18. width: 100%; /* Full width */
  19. height: 100%; /* Full height */
  20. overflow: auto; /* Enable scroll if needed */
  21. background-color: rgb(0,0,0); /* Fallback color */
  22. background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
  23. }
  24.  
  25. /* Modal Content/Box */
  26. .modal-content {
  27. background-color: #fefefe;
  28. margin: 15% auto; /* 15% from the top and centered */
  29. padding: 20px;
  30. border: 1px solid #888;
  31. width: 80%; /* Could be more or less, depending on screen size */
  32. }
  33.  
  34. /* The Close Button */
  35. .close {
  36. color: #aaa;
  37. float: right;
  38. font-size: 28px;
  39. font-weight: bold;
  40. }
  41.  
  42. .close:hover,
  43. .close:focus {
  44. color: black;
  45. text-decoration: none;
  46. cursor: pointer;
  47. }
  48. </style>
  49. <script>
  50. // Get the modal
  51. var modal = document.getElementById("myModal");
  52.  
  53. // Get the button that opens the modal
  54. var btn = document.getElementById("myBtn");
  55.  
  56. // Get the <span> element that closes the modal
  57. var span = document.getElementsByClassName("close")[0];
  58.  
  59. // When the user clicks on the button, open the modal
  60.  
  61. modal.style.display = "block";
  62.  
  63.  
  64. // When the user clicks on <span> (x), close the modal
  65. span.onclick = function() {
  66. modal.style.display = "none";
  67. }
  68.  
  69. // When the user clicks anywhere outside of the modal, close it
  70. window.onclick = function(event) {
  71. if (event.target == modal) {
  72. modal.style.display = "none";
  73. }
  74. }
  75. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement