Skip to content

Instantly share code, notes, and snippets.

@laphilosophia
Created February 21, 2019 12: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 laphilosophia/a28c1ef9a8c83c490e531a21405248fe to your computer and use it in GitHub Desktop.
Save laphilosophia/a28c1ef9a8c83c490e531a21405248fe to your computer and use it in GitHub Desktop.
simple-modal for once run
<style type="text/css">
.gaye-modal--modal {
width: 100%;
height: 100%;
position: fixed;
top: 0; left: 0;
z-index: 9999;
background-color: rgba(0, 0, 0, 0.5);
}
.gaye-modal--body {
width: 100%;
max-width: 600px;
max-height: 600px;
display: block;
position: absolute;
top: 0; left: 0;
bottom: 0; right: 0;
margin: auto;
border-radius: 3px;
overflow: hidden;
box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.7);
}
.gaye-modal--close {
display: block;
width: 80px; height: 30px;
position: absolute;
top: 10px; right: 10px;
border-radius: 3px;
box-sizing: border-box;
background-color: black;
color: white;
font-size: 12px;
font-weight: bold;
}
.gaye-modal--body img {
max-width: 100%;
display: block;
}
</style>
<script>
function modal () {
var wrapper = document.createElement('div');
wrapper.classList.add('gaye-modal--modal');
var modal = document.createElement('div');
modal.classList.add('gaye-modal--body');
var invitation = new Image();
invitation.src = 'images/invitation.png';
invitation.alt = 'Davetiye';
var close = document.createElement('button');
close.classList.add('gaye-modal--close');
close.textContent = 'Kapat';
modal.appendChild(invitation);
modal.appendChild(close);
wrapper.appendChild(modal);
(document.body).appendChild(wrapper);
localStorage.setItem('gaye-modal', true);
setTimeout(function () {
document.querySelector('.gaye-modal--close').addEventListener('click', event => {
document.querySelector('.gaye-modal--modal').remove();
localStorage.setItem('gaye-modal', false);
});
}, 500);
}
var modalKey = localStorage.getItem('gaye-modal');
if (!modalKey && modalKey != true) {
modal();
} else {
console.log('modal has been closed already!');
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment