Created
January 22, 2018 00:53
-
-
Save rg3915/a57650ba5771c1d0abc7c635e0f09ef1 to your computer and use it in GitHub Desktop.
Modal com HTML e CSS
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
<!-- Modal --> | |
<div id="myModal" class="mymodal"> | |
<!-- Modal content --> | |
<div class="mymodal-content"> | |
<div class="mymodal-header"> | |
<h4>Título</h4> | |
</div> | |
<div class="mymodal-body"> | |
... | |
</div> | |
<div class="mymodal-footer"> | |
<button class="button close">Fechar</button> | |
<button class="button button-primary">OK</button> | |
</div> | |
</div> | |
</div> | |
<script src="{% static 'js/modal.js' %}"></script> | |
{% endblock %} | |
File static/js/modal.js Added | |
// Get the modal | |
var modal = document.getElementById('myModal'); | |
// Get the button that opens the modal | |
var btn = document.getElementById("myBtn"); | |
// Get the <span> element that closes the modal | |
var span = document.getElementsByClassName("close")[0]; | |
// When the user clicks on the button, open the modal | |
btn.onclick = function() { | |
modal.style.display = "block"; | |
} | |
// When the user clicks on <span> (x), close the modal | |
span.onclick = function() { | |
modal.style.display = "none"; | |
} | |
// When the user clicks anywhere outside of the modal, close it | |
window.onclick = function(event) { | |
if (event.target == modal) { | |
modal.style.display = "none"; | |
} | |
} | |
File static/sass/partials/_modal.scss Added | |
/* The Modal (background) */ | |
.mymodal { | |
display: none; /* Hidden by default */ | |
position: fixed; /* Stay in place */ | |
z-index: 1; /* Sit on top */ | |
left: 0; | |
top: 0; | |
width: 100%; /* Full width */ | |
height: 100%; /* Full height */ | |
overflow: auto; /* Enable scroll if needed */ | |
background-color: rgb(0,0,0); /* Fallback color */ | |
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ | |
} | |
/* Modal Header */ | |
.mymodal-header { | |
border-bottom: 1px solid #e5e5e5; | |
} | |
/* Modal Body */ | |
.mymodal-body {padding: 15px;} | |
/* Modal Footer */ | |
.mymodal-footer { | |
padding-top: 15px; | |
border-top: 1px solid #e5e5e5; | |
text-align: right; | |
} | |
/* Modal Content */ | |
.mymodal-content { | |
position: relative; | |
background-color: #fefefe; | |
margin: 1% auto; | |
padding: 10px; | |
border: 1px solid #888; | |
border-radius: 6px; | |
width: 40%; | |
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19); | |
-webkit-animation-name: animatetop; | |
-webkit-animation-duration: 0.4s; | |
animation-name: animatetop; | |
animation-duration: 0.4s | |
} | |
/* Add Animation */ | |
@-webkit-keyframes animatetop { | |
from {top: -300px; opacity: 0} | |
to {top: 0; opacity: 1} | |
} | |
@keyframes animatetop { | |
from {top: -300px; opacity: 0} | |
to {top: 0; opacity: 1} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment