Advertisement
ShadowEmbrace

zad_8

Sep 11th, 2024
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7. </head>
  8. <body>
  9.     <img id="img1" src="basic/pics/img1.jpg" alt="image" width="300" height="400" onmouseover="bigImg()" onmouseout="normalImg()">
  10.  
  11.     <br>
  12.    
  13.     <button onclick="switchImage()">Switch Image</button>
  14.     <button onclick="zoom()">Zoom</button>
  15.  
  16.     <script>
  17.         function switchImage(){
  18.             let img = document.getElementById('img1');
  19.  
  20.             if (img.src.includes('img1.jpg')) {
  21.                 img.src = 'basic/pics/img2.jpeg'
  22.             }
  23.             else {
  24.                 img.src = 'basic/pics/img1.jpg'
  25.             }
  26.         }
  27.         function zoom(){
  28.             let img = document.getElementById('img1')
  29.  
  30.             if (img.width == '300'){
  31.                 img.style.width = '400px'
  32.                 img.style.height = '500px'
  33.             } else {
  34.                 img.style.width = '300px'
  35.                 img.style.height = '400px'
  36.             }
  37.         }
  38.  
  39.         function bigImg(){
  40.             let img = document.getElementById('img1')
  41.             let wdt = Number(img.width) + 50
  42.             let hgt = Number(img.height) + 50
  43.            
  44.             img.style.width = `${wdt.toString()}px`
  45.             img.style.height = `${hgt.toString()}px`
  46.         }
  47.  
  48.         function normalImg(){
  49.             let img = document.getElementById('img1')
  50.             let wdt = Number(img.width) - 50
  51.             let hgt = Number(img.height) - 50
  52.  
  53.             img.style.width = `${wdt.toString()}px`
  54.             img.style.height = `${hgt.toString()}px`
  55.         }
  56.     </script>
  57. </body>
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement