小編給大家分享一下js如何實(shí)現(xiàn)圖片放大縮小計(jì)時(shí)器效果,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
成都創(chuàng)新互聯(lián)公司專注于湘東企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),商城網(wǎng)站開(kāi)發(fā)。湘東網(wǎng)站建設(shè)公司,為湘東等地區(qū)提供建站服務(wù)。全流程按需設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
知識(shí)要點(diǎn)
var fn=setInterval(function(){},1000)
每隔1秒執(zhí)行一次函數(shù)
clearInterval(fn)
清除計(jì)時(shí)器
判斷當(dāng)圖片放大縮小到固定大小時(shí),清除計(jì)時(shí)器
完整代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>demo</title> <style> body,h2,h3,h4,h5,h6,h7,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0;} body,button,input,select,textarea{font:12px/1.5 tahoma,arial,\5b8b\4f53;} h2,h3,h4,h5,h6,h7{font-size:100%;} address,cite,dfn,em,var{font-style:normal;} code,kbd,pre,samp{font-family:courier new,courier,monospace;} small{font-size:12px;} ul,ol{list-style:none;} a{text-decoration:none;} a:hover{text-decoration:underline;} sup{vertical-align:text-top;} sub{vertical-align:text-bottom;} legend{color:#000;} fieldset,img{border:0;} button,input,select,textarea{font-size:100%;} table{border-collapse:collapse;border-spacing:0;} .clear{clear: both;float: none;height: 0;overflow: hidden;} </style> </head> <body> <div > <img src="/upload/otherpic58/77716.jpg" id="myImage" /><br> <input type="button" id="max" value="放大" /> <input type="button" id="min" value="縮小" /> </div> <script type="text/javascript"> function pic_max(){ var maxBtn=document.getElementById("max"); var minBtn=document.getElementById("min"); maxBtn.onclick=function(){ max(); } var img=document.getElementById("myImage"); var maxHeight=img.height*2; var maxWidth=img.width*2; function max(){ var endHeight=img.height*1.3; var endWidth=img.width*1.3; var maxTime=setInterval(function(){ if(img.height<endHeight&&img.width<endWidth){ if(img.height<maxHeight&&img.width<maxWidth){ img.height=img.height*1.05; img.width=img.width*1.05; }else{ alert("圖片已經(jīng)是最大值了") clearInterval(maxTime); } }else{ clearInterval(maxTime); } },20); } minBtn.onclick=function(){ min(); } var img=document.getElementById("myImage"); var minHeight=img.height*0.5; var minWidth=img.width*0.5; function min(){ var overHeight=img.height*0.7; var overWidth=img.width*0.7; var minTime=setInterval(function(){ if(img.height>overHeight&&img.width>overWidth){ if(img.height>minHeight&&img.width>minWidth){ img.height=img.height*0.95; img.width=img.width*0.95; }else{ alert("圖片已經(jīng)是最小值了") clearInterval(minTime); } }else{ clearInterval(minTime); } },20); } } window.onload=function(){ pic_max(); } </script> </body> </html>
以上是“js如何實(shí)現(xiàn)圖片放大縮小計(jì)時(shí)器效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
標(biāo)題名稱:js如何實(shí)現(xiàn)圖片放大縮小計(jì)時(shí)器效果
轉(zhuǎn)載源于:http://sd-ha.com/article2/josoic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開(kāi)發(fā)、商城網(wǎng)站、網(wǎng)站設(shè)計(jì)、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)