您好,登錄后才能下訂單哦!
<!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)+')'; //通過if-else里的取整解決ie里透明度獲取值存在偏差問題 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>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。