Skip to content

Instantly share code, notes, and snippets.

@janzenz
Created March 18, 2020 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janzenz/caca8b22786f42ae67e40ed7fb9965f4 to your computer and use it in GitHub Desktop.
Save janzenz/caca8b22786f42ae67e40ed7fb9965f4 to your computer and use it in GitHub Desktop.
<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