js实现运动的框架实例

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.οnlοad=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].οnmοuseοver=function(){
var g=this;
getmove(this,{height:100,width:400},function(){
getmove(g,{opacity:100})
});
};
test1[i].οnmοuseοut=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];
}
}

转载于:https://www.cnblogs.com/actiondream/p/5790209.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值