Created
April 27, 2017 17:00
-
-
Save stuartpearman/47d19446e9febf041c838610300eba0d to your computer and use it in GitHub Desktop.
Simple vanilla modal
This file contains 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
<div class="modal-outer"> | |
<div class="modal-box"> | |
<div class="modal-content"> | |
<!-- CONTENT HERE --> | |
</div> | |
</div> | |
<button class="exit-modal">X</button> | |
</div> |
This file contains 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
var connectButton = document.querySelector('.connect-button') | |
var modalOuter = document.querySelector('.modal-outer') | |
var modalBox = document.querySelector('.modal-box') | |
var exitModal = document.querySelector('.exit-modal') | |
function openModal () { | |
modalOuter.classList.add('active') | |
window.setTimeout(openModalBox, 200) | |
} | |
function openModalBox () { | |
modalBox.classList.add('active') | |
} | |
function closeModal () { | |
modalOuter.classList.remove('active') | |
window.setTimeout(closeModalBox, 200) | |
} | |
function closeModalBox () { | |
modalBox.classList.remove('active') | |
} | |
connectButton.addEventListener('click', openModal) | |
exitModal.addEventListener('click', closeModal) | |
window.addEventListener('keydown', function (e) { | |
console.log(e.keyCode) | |
if (e.keyCode === 27) { | |
console.log('hello') | |
closeModal() | |
} | |
}) |
This file contains 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
.modal-outer { | |
z-index: -1; | |
position: fixed; | |
top: 0; | |
bottom: 0; | |
left: 0; | |
right: 0; | |
background: rgba(255,255,255,1); | |
padding: 20px; | |
opacity: 0; | |
transition: opacity 0.2s; | |
display: flex; | |
justify-content: center; | |
flex-direction: column; | |
} | |
.modal-outer.active { | |
opacity: 1; | |
z-index: 1; | |
} | |
.modal-box { | |
height: 0; | |
border: 2px solid rgba(0,0,0,0.2); | |
width: 800px; | |
margin: 0 auto; | |
transition: height 0.8s; | |
overflow: hidden; | |
} | |
.modal-content { | |
box-sizing: border-box; | |
padding: 40px; | |
height: 100%; | |
display: flex; | |
flex-direction: column; | |
justify-content: center; | |
text-align: center; | |
opacity: 0; | |
transition: opacity 0.8s; | |
transition-delay: 0.4s; | |
color: #6c7273; | |
} | |
.modal-box.active { | |
height: 400px; | |
} | |
.modal-box.active .modal-content { | |
opacity: 1; | |
} | |
.exit-modal { | |
position: fixed; | |
top: 20px; | |
left: 20px; | |
display: inline-block; | |
padding: 10px; | |
font-size: 2em; | |
font-weight: 100; | |
height: auto; | |
border: 0; | |
color: rgba(0,0,0,0.6) | |
} | |
.modal-content .contact-list li { | |
display: block; | |
} | |
@media (max-width: 840px) { | |
.modal-box { | |
width: 100%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment