Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

logan_pa

[Resolvido] modal automático

Recommended Posts

Olá! Estou procurando um código de Janela modal com jQuery e encontrei esse no site do Maujor mas só funciona quando clicado no link. Como faço para funcionar ao abrir o site?

 

Código:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>jQuery Modal Window</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> 
<script type="text/javascript">

$(document).ready(function() {	

$('a[name=modal]').click(function(e) {
	e.preventDefault();

	var id = $(this).attr('href');

	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	$('#mask').css({'width':maskWidth,'height':maskHeight});

	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo("slow",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);

	$(id).fadeIn(2000); 

});

$('.window .close').click(function (e) {
	e.preventDefault();

	$('#mask').hide();
	$('.window').hide();
});		

$('#mask').click(function () {
	$(this).hide();
	$('.window').hide();
});			

});

</script>
<style type="text/css">
body {
font-family:verdana;
font-size:15px;
}

a {color:#333; text-decoration:none}
a:hover {color:#ccc; text-decoration:none}

#mask {
 position:absolute;
 left:0;
 top:0;
 z-index:9000;
 background-color:#000;
 display:none;
}

#boxes .window {
 position:absolute;
 left:0;
 top:0;
 width:440px;
 height:200px;
 display:none;
 z-index:9999;
 padding:20px;
}

#boxes #dialog {
 width:375px; 
 height:203px;
 padding:10px;
 background-color:#ffffff;
}

#boxes #dialog1 {
 width:375px; 
 height:203px;
}

#dialog1 .d-header {
 background:url(login-header.png) no-repeat 0 0 transparent; 
 width:375px; 
 height:150px;
}

#dialog1 .d-header input {
 position:relative;
 top:60px;
 left:100px;
 border:3px solid #cccccc;
 height:22px;
 width:200px;
 font-size:15px;
 padding:5px;
 margin-top:4px;
}

#dialog1 .d-blank {
 float:left;
 background:url(login-blank.png) no-repeat 0 0 transparent; 
 width:267px; 
 height:53px;
}

#dialog1 .d-login {
 float:left;
 width:108px; 
 height:53px;
}

#boxes #dialog2 {
 background:url(notice.png) no-repeat 0 0 transparent; 
 width:326px; 
 height:229px;
 padding:50px 0 20px 25px;
}
.close{display:block; text-align:right;}

</style>
</head>
<body>

<ul>

<li><a href="#dialog" name="modal">Janela Modal Simples</a></li>

</ul>


<div id="boxes">

<div id="dialog" class="window">
<a href="#" class="close">Fechar [X]</a><br />
Janela Modal Simples<br />  
Aqui vai o conteúdo da sua Janela Modal Simples.
</div>




<!-- Máscara para cobrir a tela -->
 <div id="mask"></div>

</div>


</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

É... ai você substitui os ID's:

 

<script type="text/javascript">

$(function() {  

       var id = $("#dialog").attr('href');
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	$('#mask').css({'width':maskWidth,'height':maskHeight});

	$('#mask').fadeIn(1000);        
	$('#mask').fadeTo("slow",0.8);  

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	$("#dialog").css('top',  winH/2-$(id).height()/2);
	$("#dialog").css('left', winW/2-$(id).width()/2);

	$("#dialog").fadeIn(2000); 

       $('.window .close').click(function (e) {
               e.preventDefault();

               $('#mask').hide();
               $('.window').hide();
       });             

       $('#mask').click(function () {
               $(this).hide();
               $('.window').hide();
       });                     

});

</script>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Valeu, era isso mesmo.

 

Agora é só alinhar a janela no centro da tela, aqui esta aparecendo no canto superior esquerdo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.