js實現運動的架構執行個體

來源:互聯網
上載者:User

標籤:

html代碼:滑鼠移入時多物體實現高寬同時變化接著改變透明度

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="t.css">
<script type="text/javascript" src="jstest.js"></script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>

js代碼:

window.onload=function(){
var test1=document.getElementsByTagName(‘li‘);
for(var i=0;i<test1.length;i++)
{
test1[i].timer=null;
test1[i].alpha=30;
//test1[i].speed=0;
test1[i].onmouseover=function(){
var g=this;
getmove(this,{height:100,width:400},function(){
getmove(g,{opacity:100})
});
};
test1[i].onmouseout=function(){
var g=this;
getmove(this,{opacity:30},function(){
getmove(g,{height:70,width:300})
});
};
}
};
//a1是目標值,obj為對象,attrr是需要的屬性,fn回呼函數

function getmove(obj,json,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var flag=1;
//jason迴圈
for(var attrr in json){
//擷取當前樣式值
if(attrr==‘opacity‘){
icur=Math.round(parseFloat(getStyle(obj,attrr))*100);
}else{
icur=parseInt(getStyle(obj,attrr));
}
//計算速度
var speed=(json[attrr]-icur)/10;
speed=speed>0? Math.ceil(speed):Math.floor(speed);
//判斷是否全部達到目標值
if(icur!=json[attrr]){
flag=0;
}
//計算結果
if(attrr==‘opacity‘)
{
obj.style.filter=‘alpha(opacity:‘+(icur+speed)+‘)‘;
obj.style.opacity=(icur+speed)/100;
}
else{
obj.style[attrr]=icur+speed+‘px‘;
}
}
//判斷是否的關閉定時器
if(flag){
clearInterval(obj.timer);
if(fn){
fn();
}

}
},30);}
//擷取當前樣式值的函數運算式
function getStyle(obj,attrr){
if(obj.currentStyle){
return obj.currentStyle[attrr];
}else{
return getComputedStyle(obj,false)[attrr];
}
}

js實現運動的架構執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.