Created
April 15, 2015 15:39
-
-
Save avuenja/f21cab1326d5848c23ac to your computer and use it in GitHub Desktop.
Janela Modal Simples
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
<!DOCTYPE html> | |
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$("a[rel=modal]").click(function(ev) { | |
ev.preventDefault(); | |
var id = $(this).attr("href"); | |
var alturaTela = $(document).height(); | |
var larguraTela = $(window).width(); | |
//colocando o fundo preto | |
$('#mascara').css({ | |
'width' : larguraTela, | |
'height' : alturaTela | |
}); | |
$('#mascara').fadeIn(1000); | |
$('#mascara').fadeTo("slow", 0.8); | |
var left = ($(window).width() / 2) - ($(id).width() / 2 ); | |
var top = ($(window).height() / 2) - ($(id).height() / 2 ); | |
$(id).css({ | |
'top' : top, | |
'left' : left | |
}); | |
$(id).show(); | |
}); | |
$("#mascara").click(function() { | |
$(this).hide(); | |
$(".window").hide(); | |
}); | |
$('.fechar').click(function(ev) { | |
ev.preventDefault(); | |
$("#mascara").hide(); | |
$(".window").hide(); | |
}); | |
}); | |
</script> | |
<style> | |
.window { | |
display: none; | |
width: 300px; | |
height: 300px; | |
position: absolute; | |
left: 0; | |
top: 0; | |
background: #FFF; | |
z-index: 9900; | |
padding: 10px; | |
border-radius: 10px; | |
} | |
#mascara { | |
display: none; | |
position: absolute; | |
left: 0; | |
top: 0; | |
z-index: 9000; | |
background-color: #000; | |
} | |
.fechar { | |
display: block; | |
text-align: right; | |
} | |
</style> | |
<a href="#janela1" rel="modal">Janela modal</a> | |
<div class="window" id="janela1"> | |
<a href="#" class="fechar">X Fechar</a> | |
<h4>Primeira janela modal</h4> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam venenatis auctor tempus. Lorem ipsum dolor sit amet, | |
</p> | |
<p> | |
Morbi dui lacus, placerat eget pretium vehicula, mollis id ligula. Nulla facilisi. | |
</p> | |
</div> | |
<!-- mascara para cobrir o site --> | |
<div id="mascara"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment