Last active
June 27, 2019 17:04
-
-
Save orblazer/d25f3717787d69cf25c4ca36ac2a008d to your computer and use it in GitHub Desktop.
Modal JS by Orblazer
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-open { | |
overflow: hidden; | |
} | |
.modal { | |
position: fixed; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
background-color: rgba(0, 0, 0, 0.5); | |
z-index: 10; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
opacity: 0; | |
visibility: hidden; | |
-webkit-transition: all .3s; | |
-moz-transition: all .3s; | |
-o-transition: all .3s; | |
transition: all .3s; | |
} | |
.modal.open { | |
opacity: 1; | |
visibility: visible; | |
} | |
.modal > .modal-container { | |
position: relative; | |
width: 980px; | |
max-height: 90%; | |
min-height: 50%; | |
background-color: white; | |
border-radius: 5px; | |
overflow: auto; | |
margin-top: -200%; | |
opacity: 0; | |
-webkit-transition: margin .3s, opacity .3s; | |
-moz-transition: margin .3s, opacity .3s; | |
-o-transition: margin .3s, opacity .3s; | |
transition: margin .3s, opacity .3s; | |
} | |
.modal.open > .modal-container { | |
margin-top: 0; | |
opacity: 1; | |
} | |
/** | |
* Modal > close | |
*/ | |
.modal > .modal-container > .close { | |
position: absolute; | |
color: white; | |
font-size: 1.35em; | |
top: 10px; | |
right: 12px; | |
background-color: rgba(0, 0, 0, 0.5); | |
padding: 0 8px; | |
cursor: pointer; | |
z-index: 10; | |
-moz-border-radius: 2px; | |
-webkit-border-radius: 2px; | |
border-radius: 2px; | |
} | |
.modal > .modal-container > .close:hover { | |
color: black; | |
} | |
/** | |
* Modal > header | |
*/ | |
.modal > .modal-container > .modal-header { | |
display: flex; | |
justify-content: space-between; | |
} | |
.modal > .modal-container > .modal-header > .slider { | |
width: 49%; | |
min-height: 300px; | |
} | |
.modal > .modal-container > .modal-header > .header-content { | |
width: 49%; | |
} | |
.modal > .modal-container > .modal-header > .header-content > .title { | |
margin: 0; | |
font-size: 2em; | |
color: #e8396f; | |
padding-top: 15px; | |
} | |
.modal > .modal-container > .modal-header > .header-content > .description { | |
color: #fab626; | |
} | |
.modal > .modal-container > .modal-header > .header-content > p { | |
padding-right: 15px; | |
} | |
/** | |
* Modal > content | |
*/ | |
.modal > .modal-container > .modal-content { | |
min-width: 50px; | |
padding: 20px; | |
} | |
.modal > .modal-container > .modal-content > h2 { | |
margin: 15px 0 0; | |
font-size: 1.3em; | |
color: #0eb7a3; | |
} | |
.modal > .modal-container > .modal-content > h2:first-child { | |
margin-top: 0; | |
} | |
.modal > .modal-container > .modal-content > p { | |
margin: 0; | |
} | |
/** | |
* Modal > footer | |
*/ | |
.modal > .modal-container > .modal-footer { | |
display: flex; | |
justify-content: space-between; | |
background-color: #2b2b2b; | |
color: white; | |
padding: 15px; | |
} | |
.modal > .modal-container > .modal-footer > .links { | |
margin: 0; | |
padding: 0; | |
list-style: none; | |
} | |
.modal > .modal-container > .modal-footer > .logo > img { | |
max-height: 80px; | |
} |
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 currModal = undefined; | |
var Modal = function (elem) { | |
var self = this; | |
var element = elem; | |
var closeElem = elem.querySelector('.modal-container>.close'); | |
if (closeElem instanceof HTMLElement) { | |
closeElem.addEventListener('click', function () { | |
self.close(); | |
}); | |
} | |
this.open = function () { | |
if (currModal !== undefined) { | |
currModal.close(); | |
} | |
if (document.body.className.indexOf('modal-open') === -1) { | |
document.body.className += ' modal-open'; | |
} | |
if (element.className.indexOf('open') === -1) { | |
element.className += ' open'; | |
} | |
currModal = self; | |
}; | |
this.close = function () { | |
if (document.body.className.indexOf('modal-open') !== -1) { | |
document.body.className = document.body.className.replace(' modal-open', ''); | |
} | |
if (element.className.indexOf('open') !== -1) { | |
element.className = element.className.replace(' open', ''); | |
} | |
currModal = undefined | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment