Created
March 18, 2020 11:39
-
-
Save janzenz/caca8b22786f42ae67e40ed7fb9965f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
#gtm-popup { | |
width: 70vw; | |
height: 70vh; | |
position: fixed; | |
background-color: gray; | |
color: white; | |
/* Align content to the middle. */ | |
display: none; /* hide by default */ | |
flex-direction: column; | |
align-items: center; | |
justify-content: center; | |
/* Sticking modal to the middle */ | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
} | |
#gtm-popup-btn { | |
display: block; | |
border: 1px solid #ccc; | |
padding: 20px; | |
background-color: orange; | |
color: white; | |
font-size: 20px; | |
} | |
.gtm-show { display: flex !important; } | |
</style> | |
<div id="gtm-popup" class=""> | |
<h3>Hello world</h3> | |
<p>Content here...</p> | |
<button id="gtm-popup-btn">Covid Updates</button> | |
</div> | |
<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script> | |
<script> | |
(function() { | |
document.querySelector('#gtm-popup-btn').addEventListener('click', function() { | |
Cookies.set('gtmPopup', '1', { expires: 99999 }); | |
document.querySelector('#gtm-popup').classList.remove('gtm-show'); | |
}); | |
/* already closed */ | |
if (!Cookies.get('gtmPopup')) { | |
document.querySelector('#gtm-popup').classList.add('gtm-show'); | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment