js物体运动-图标向上运动再从下方出现运动到原位置

24 篇文章 0 订阅
15 篇文章 0 订阅
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<title>图标动画效果演示</title>
<style>
*{margin: 0;padding: 0;}
#move{height:200px;width:300px;margin: 10px auto;background: #eee;border: 1px solid #ccc;}
#move a{display:inline-block;height:25px;width:58px;background: #fff;margin: 10px 17px;border: 1px solid #ddd;border-radius: 3px;text-align: center;position: relative; padding-top:40px;color:#9c9c9c; font-size:12px; text-decoration:none;line-height:25px;overflow: hidden;}
#move a i{position:absolute;top:20px;left:0;display:inline=block; width:100%;text-align:center;filter:alpha(opacity=100);opacity:1;}
#move a:hover{color:#F00;}
#move img{border:none;}
</style>
</head>
<body>
	<div id="move">
		<a href="#"><i><img src="images/food.png"/></i><p>食品</p></a>
		<a href="#"><i><img src="images/game.png"/></i><p>游戏</p></a>
		<a href="#"><i><img src="images/insurance.png"/></i><p>保险</p></a>
		<a href="#"><i><img src="images/lottery.png"/></i><p>日期</p></a>
		<a href="#"><i><img src="images/movie.png"/></i><p>电影</p></a>
		<a href="#"><i><img src="images/travel.png"/></i><p>旅行</p></a>
	</div>
</body>
</html>
<script type="text/javascript">
window.οnlοad=function(){
	var oMove=document.getElementById('move');
	var aList=document.getElementsByTagName('a');
	for (var i = 0; i < aList.length; i++) {
		aList[i].οnmοuseenter=function(){
			var _this=this.getElementsByTagName('i')[0];
			startMove(_this,{top:-25,opacity:0},function(){
				_this.style.top=40+'px';
				startMove(_this,{top:20,opacity:100});
			});
		};
	};
};
	function startMove(obj,json,fn){
		clearInterval(obj.timer);
		obj.timer=setInterval(function(){
			var flag=true;//假设都结束时为true
			for(var attr in json){
				//取当前值
				var icur=0;
				if(attr=='opacity'){
					icur=Math.round(parseFloat(getStyle(obj,attr))*100);
				}else{
					icur=parseInt(getStyle(obj,attr));
				}
				//算速度
				var speed=(json[attr]-icur)/10;
				speed=speed>0?Math.ceil(speed):Math.floor(speed);
				if(parseInt(icur)!=parseInt(json[attr])){
					flag=false;
				}
				if(attr=='opacity'){
					obj.style.filter='alpha(opacity:'+(icur+speed)+')';
					obj.style.opacity=(icur+speed)/100;
				}else{
					obj.style[attr]=icur+speed+"px";
				}
			}
			if(flag){
				clearInterval(obj.timer);
				if(fn){
					fn();
				}
			}
		},3);
	}
	
	function getStyle(obj,attr){
		if(obj.currentStyle){
			return obj.currentStyle[attr];  //IE
		}else{
			return getComputedStyle(obj,false)[attr];   //火狐
		}
	}
</script>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值