Advertisement
retnet

js overlay

Feb 21st, 2024
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const modal = document.querySelector(".modal");
  2. const modalOverlay = document.querySelector(".modal-overlay");
  3. const closeBtn = document.querySelector(".modal .close-btn");
  4. const discountBtn = document.querySelector(".modal .discount-btn");
  5.  
  6. const createCookie = () => {
  7.   let maxAge = ";max-age=10";
  8.   let path = ";path=/";
  9.   document.cookie = "live-blogger-popup=displayed" + maxAge + path;
  10. };
  11.  
  12. const displayModal = () => {
  13.   if (document.cookie.indexOf("live-blogger-popup") == -1) {
  14.     modal.classList.add("active");
  15.     modalOverlay.classList.add("active");
  16.     createCookie();
  17.   }
  18. };
  19.  
  20. setTimeout(() => {
  21.   displayModal();
  22. }, 2000);
  23.  
  24. closeBtn.addEventListener("click", () => {
  25.   modal.classList.remove("active");
  26.   modalOverlay.classList.remove("active");
  27. });
  28.  
  29. discountBtn.addEventListener("click", () => {
  30.   modal.classList.remove("active");
  31.   modalOverlay.classList.remove("active");
  32. });
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement