Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <img id="img1" src="basic/pics/img1.jpg" alt="image" width="300" height="400" onmouseover="bigImg()" onmouseout="normalImg()">
- <br>
- <button onclick="switchImage()">Switch Image</button>
- <button onclick="zoom()">Zoom</button>
- <script>
- function switchImage(){
- let img = document.getElementById('img1');
- if (img.src.includes('img1.jpg')) {
- img.src = 'basic/pics/img2.jpeg'
- }
- else {
- img.src = 'basic/pics/img1.jpg'
- }
- }
- function zoom(){
- let img = document.getElementById('img1')
- if (img.width == '300'){
- img.style.width = '400px'
- img.style.height = '500px'
- } else {
- img.style.width = '300px'
- img.style.height = '400px'
- }
- }
- function bigImg(){
- let img = document.getElementById('img1')
- let wdt = Number(img.width) + 50
- let hgt = Number(img.height) + 50
- img.style.width = `${wdt.toString()}px`
- img.style.height = `${hgt.toString()}px`
- }
- function normalImg(){
- let img = document.getElementById('img1')
- let wdt = Number(img.width) - 50
- let hgt = Number(img.height) - 50
- img.style.width = `${wdt.toString()}px`
- img.style.height = `${hgt.toString()}px`
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement