<!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>任意值運(yùn)動(dòng)框架</title> <style> div{width:200px;height:200px;background:red;float:left;border:10px black solid;margin:50px;font-size:50px;color:yellow;} #div4{filter:alpha(opacity:30);opacity:0.3;} </style> <script> window.onload=function (){ var oDiv1=document.getElementById('div1'); var oDiv2=document.getElementById('div2'); var oDiv3=document.getElementById('div3'); var oDiv4=document.getElementById('div4'); oDiv1.onmouseover=function (){ StartMove(this,'width',500); }; oDiv1.onmouseout=function (){ StartMove(this,'width',200); }; oDiv2.onmouseover=function (){ StartMove(this,'height',500); }; oDiv2.onmouseout=function (){ StartMove(this,'height',100); }; oDiv3.onmouseover=function (){ StartMove(this,'font-size',100); }; oDiv3.onmouseout=function (){ StartMove(this,'font-size',50); }; oDiv4.onmouseover=function (){ StartMove(this,'opacity',100); }; oDiv4.onmouseout=function (){ StartMove(this,'opacity',30); }; }; function getstyle(obj,name) { if(obj.currentStyle) //針對(duì)ie獲取 { return obj.currentStyle[name]; } else //針對(duì)非行間樣式 { return getComputedStyle(obj,null)[name]; } }; function StartMove(obj,ss,itarget) { clearInterval(obj.timer); obj.timer=setInterval(function (){ var cur=0; if(ss=='opacity'){ cur=parseFloat(getstyle(obj,ss))*100 } else { cur=parseInt(getstyle(obj,ss)); } var speed=(itarget-cur)/4; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(itarget-cur==0){ clearInterval(obj.timer); } else{ if(ss=='opacity') { obj.style.filter='alpha(opacity='+(cur+speed)+')'; //通過(guò)if-else里的取整解決ie里透明度獲取值存在偏差問(wèn)題 if((cur+speed)>=30) { obj.style.opacity=Math.ceil((cur+speed))/100; } else { obj.style.opacity=Math.floor((cur+speed))/100; } document.getElementById('txt1').value=cur+speed; } else { obj.style[ss]=cur+speed+'px'; } } },30); }; </script> </head> <body> <div id="div1"> 變寬</div> <div id="div2"> 變高</div> <div id="div3"> 字符變大</div> <div id="div4"> <input id="txt1" type="text" ? /> </div> </body> </html>
網(wǎng)站題目:js之任意值運(yùn)動(dòng)框架
本文來(lái)源:http://muchs.cn/article46/ghjihg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、微信小程序、網(wǎng)站建設(shè)、域名注冊(cè)、網(wǎng)站內(nèi)鏈、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(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)