آموزش جاوااسکریپت › انجمن ها › جاوا اسکریپت › عمل نکردن shrink و expand › پاسخ به: عمل نکردن shrink و expand
سپتامبر 18, 2021 در 11:17 ق.ظ
#58780
مهدی حسن زاده
مدیرکل
سلام
من سورس کد رو ندارم.در ادامه سورس کد یکی از دانشجوهای دوره رو میزارم که کار میکنه به درستی و میتونید کد خودتون رو باهاش مقایسه کنید
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
let val; let val2; let width = 700; function increase(){ clearInterval(val2) val = setInterval(up,20) } function up(){ if(width < 800){ width = width + 2 document.getElementById('img1').width = width } else{ clearInterval(val) } } function decrease(){ clearInterval(val) val2 = setInterval(bot,20) } function bot(){ if(width > 700){ width = width - 2 document.getElementById('img1').width = width } else{ clearInterval(val2) } } |
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="5.js"></script> <title>Document</title> </head> <body> <img id="img1" src="27.jfif" alt="" onmouseover="increase()" onmouseout="decrease()" width="700px" height="550px"> </body> </html> |