The examples in this article share the image slowly enlarge and reduce the js implementation code for your reference. The specific content is as follows
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Slow scaling of pictures</title></head><script> window.onload = function(){ var btn_big = document.getElementById("big"); var btn_small = document.getElementById("small"); var pic = document.getElementById("pic"); //Slowly zoom btn_big.onclick = function(){ var width = parseInt(pic.style.width); var i = width; var count = 0; console.log(width); var timer = setInterval(function(){ count++; i++; pic.style.width = i + "%"; if(count == 10 ){ clearInterval(timer); }else if( i > 50){ btn_big.onclick = function(e){ btn_big.onclick = null; }; } },13); }; //Slowly shrink btn_small.onclick = function(){ var width = parseInt(pic.style.width); var count = 0; if(width == 10){ alert("The picture is already minimal!!"); return false; } console.log(width); var timer2 = setInterval(function(){ count++; width--; pic.style.width = width +"%"; if(count == 10){ clearInterval(timer2); }else if( width < 10){ btn_small.onclick = null; } },13); } } }</script><style> #pic{ width: 20%; }</style><body> <div id="pic"> <img src="3.pic.jpg"> </div> <div> <button id="big">Zoom in</button> <button id="small">Zoom out</button> </div></body></html>The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.