RyanJ93

Piccolo esempio di dialog modale

Nov 6th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.67 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Piccolo esempio di dialog modale</title>
  6. <style type="text/css">
  7. /*CODICE CSS PER LA DIALOG E SFONDO*/
  8. .dialog{
  9.     margin:auto;
  10.     width:500px;
  11.     height:140px;
  12.     border:1px solid #CCC;
  13.     padding:10px;
  14.     left:0px;
  15.     top:0px;
  16.     bottom:0px;
  17.     right:0px;
  18.     position:fixed;
  19.     background-color:#FFF;
  20.     display:none;
  21.     z-index:1000;
  22.     border-radius:3px;
  23. }
  24.  
  25. .overlay{
  26.     position:fixed;
  27.     width:100%;
  28.     height:100%;
  29.     background-color:#000;
  30.     background-color:rgba(0, 0, 0, 0.5);
  31.     z-index:999;
  32.     left:0px;
  33.     top:0px;
  34.     display:none;
  35. }
  36.  
  37. //CODICE CSS PER IL RESTO DELLA PAGINA
  38.  
  39. .text{
  40.     font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
  41.     font-size:14px;
  42.     color:#333;
  43. }
  44.  
  45. .big{
  46.     font-size:24px;
  47. }
  48.  
  49. .dialog-newsletter-mail{
  50.     width:400px;
  51.     float:right;
  52. }
  53.  
  54. .dialog-newsletter-button{
  55.     width:100px;
  56.     height:30px;
  57.     float:right;
  58.     cursor:pointer;
  59.     border:1px solid #CCC;
  60.     background-color:#EEE;
  61.     border-radius:3px;
  62.     text-align:center;
  63. }
  64.  
  65. .dialog-newsletter-button:hover{
  66.     background-color:#CCC;
  67. }
  68. </style>
  69. <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  70. <script type="text/javascript">
  71. function validateEmail(email) {
  72.     if ( email == "" ){
  73.         return false;
  74.     }
  75.     var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  76.     return re.test(email);
  77. }
  78.  
  79. function showDialog(){
  80.     //MOSTRA LA DIALOG
  81.     $("#dialog-newsletter").fadeIn(250);
  82.     $("#overlay-newsletter").fadeIn(250);
  83.     return true;
  84. }
  85.  
  86. function activateNewsletter(){
  87.     var mail = $("#dialog-newsletter-mail").val();
  88.     //PRIMA DI FARE QUALSIASI COSA VALIDA LA MAIL
  89.     if ( validateEmail(mail) == false ){
  90.         alert("La mail inserita non è valida!");
  91.         return false;
  92.     }
  93.     //FAI L'ISCRIZIONE CON LA MAIL INSERITA
  94.     //CHIUDI LA DIALOG
  95.     $("#dialog-newsletter").fadeOut(250);
  96.     $("#overlay-newsletter"). fadeOut(250);
  97.     return true;
  98. }
  99.  
  100. //MOSTRI LA DIALOG AL CARICAMENTO DELLA PAGINA
  101. $(function(){
  102.     showDialog();
  103. });
  104. </script>
  105. </head>
  106. <body>
  107. <div class="dialog" id="dialog-newsletter">
  108.     <!--
  109.     IL RELATIVO CONTENUTO E STILE TE LO GESTIRAI POI IN BASE ALLE TUE ESIGENZE...
  110.     <!-->
  111.     <span class="text big">Iscriviti alla newsletter</span>
  112.     <br /><br />
  113.     <span class="text">Mail:</span>&nbsp;<input required type="email" id="dialog-newsletter-mail" placeholder="inserisci qui la tua mail" class="text dialog-newsletter-mail" />
  114.     <br /><br /><br />
  115.     <button onClick="activateNewsletter();" class="dialog-newsletter-button text">OK</button>
  116. </div>
  117. <div class="overlay" id="overlay-newsletter"></div>
  118. </body>
  119. </html>
Advertisement
Add Comment
Please, Sign In to add comment