Advertisement
fcamuso

Javascript Lezione 53

Jun 30th, 2022
1,441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="EN">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <title>DOM</title>
  6.  
  7.     <link rel="stylesheet" href="style.css">
  8.  
  9.     <style>
  10.         img {width: 50px; height: 50px;}
  11.         td, #img1 {border: 1px solid black;}
  12.         .testoRosso {color: red;}
  13.         .sfondoGiallo {background-color: yellow;}
  14.         .font35 {font-size: 35px;}
  15.         .font25 {font-size: 25px;}
  16.         span {font-size: 25px;}
  17.     </style>
  18.  
  19. </head>
  20. <body>
  21.     <div id='div1'>
  22.         <p id="p1" class="testoRosso sfondoGiallo">primo paragrafo</p>
  23.         <p id="p2">secondo paragrafo
  24.                    <img id="img1" src="teatro1.png">
  25.                    <img id="img2" src="teatro2.png">
  26.         </p>
  27.     </div>
  28.  
  29.     <div id='div2'>
  30.         <a href="https://www.bbc.com">sito bbc</a>
  31.     </div>
  32.  
  33.     Londra <input class="c1" type="checkbox" name="capitali" id="cb1">
  34.     Parigi <input class="c1" type="checkbox" name="capitali" id="cb2">
  35.     Roma   <input type="checkbox" name="capitali" id="cb3">
  36.     Madrid <input type="checkbox" name="capitali" id="cb4"> <br> <br>
  37.     Luogo nascita <input type="text" id="localita"> <br> <br>
  38.     Lingua madre <input type="text" id="lingua">
  39.  
  40.  
  41.     <script>  
  42.      
  43.        const applica_bordo = function () { this.style.border = '2px solid red';}
  44.        const img2 = document.getElementById('img2');
  45.        const img1 = document.getElementById('img1');
  46.  
  47.  
  48.        img1.addEventListener('mouseover', function () { img2.removeEventListener('mouseover', applica_bordo);} )
  49.  
  50.        img1.addEventListener('click', function (datiEvento) {
  51.         let confini = this.getBoundingClientRect();
  52.      
  53.         if (datiEvento.clientX>confini.right-this.width + this.width/2 -10 &&
  54.             datiEvento.clientX<confini.right-this.width + this.width/2  + 10 &&
  55.             datiEvento.clientY>confini.bottom-this.height + this.height/2 - 10 &&
  56.             datiEvento.clientY<confini.bottom-this.height + this.height/2 + 10 )
  57.               img1.style.display='none';
  58.         } );
  59.  
  60.        img2.addEventListener('mouseover', function () {
  61.           this.style.width = '100px';
  62.           this.style.height = '100px';
  63.        });
  64.        img2.addEventListener('mouseover', applica_bordo);
  65.  
  66.        img2.addEventListener('mouseleave', function () {
  67.           this.style.width = '50px';
  68.           this.style.height = '50px';
  69.           this.style.border = '';
  70.           img1.style.display='normal';
  71.        });      
  72.  
  73.        const localita = document.getElementById('localita')
  74.          .addEventListener('keydown', function (datiEvento) {
  75.             if (datiEvento.key === "Enter" && datiEvento.ctrlKey)
  76.               document.getElementById('lingua').focus();
  77.  
  78.        })
  79.  
  80.        function setWidthHeight(element, width, height)
  81.        {element.style.width = width; element.style.height = height;  }
  82.     </script>
  83. </body>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement