js基本知识比较系列四:动画

javascript原生运动

function startMove(obj, json, fn) {
	clearInterval(obj.iTimer);
	var iCur = 0;
	var iSpeed = 0;
		
	obj.iTimer = setInterval(function() {
		
		var iBtn = true;
					
		for ( var attr in json ) {
							
			var iTarget = json[attr];
			
			if (attr == 'opacity') {
				iCur = Math.round(css( obj, 'opacity' ) * 100);
			} else {
				iCur = parseInt(css(obj, attr));
			}
			
			iSpeed = ( iTarget - iCur ) / 8;
			iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
			
			if (iCur != iTarget) {
				iBtn = false;
				if (attr == 'opacity') {
					obj.style.opacity = (iCur + iSpeed) / 100;
					obj.style.filter = 'alpha(opacity='+ (iCur + iSpeed) +')';
				} else {
					obj.style[attr] = iCur + iSpeed + 'px';
				}
			}
			
		}
		
		if (iBtn) {
			clearInterval(obj.iTimer);
			fn && fn.call(obj);
		}
		
	}, 30);
}

function css(obj, attr) {
	if (obj.currentStyle) {
		return obj.currentStyle[attr];
	} else {
		return getComputedStyle(obj, false)[attr];
	}
}


jquery :

动画方法: hide()  show()  fadeIn()  fadeOut()  slideUp()  slideDown()  

 fast:200毫秒  normal: 400毫秒  slow:600毫秒

自定义动画:

$(selector).animate({params},speed,callback);

可选的 speed 参数规定效果的时长。它可以取以下值:"slow"、"fast" 或毫秒。

(1)累加 : animate({left:"+=500px"},300);

(2)多重动画:animate({left:"500px",height:'200px'},3000)

(3)停止动画: stop(clearQueue,gotoEnd)

(4)是否在动画中: is(":aniamted")

(5)延迟动画: delay()

(6)其他动画: toggle(speed,[callback])  slideToggle(speed,[easing],[callback])  fadeTo(speed,opacity,[callback])  fadeToggle(speed,[easing],[callback])

fadeTo(600,0.2);

(7)缓冲效果 :

使用jquery.easing.js插件

$('.div4').animate({
width:'500px',
opacity: 1 
   },1000,'easeOutBounce');

多个属性

$(myElement).animate({  
    left: [500, 'swing'],  
    top: [200, 'easeOutBounce']  
});  




css3动画

animation:

animation: name duration timing-function delay iteration-count direction;
.div3{
			width:100px;
			height:100px;
			border:1px solid blue;
			animation:myfirst 5s linear 2s infinite alternate;			
		}	
		@keyframes myfirst{
			0%   {background: red;}
		        25%  {background: yellow;}
                        50%  {background: blue;}
                        100% {background: green;}
		}


svg动画  推荐文章:http://www.zhangxinxu.com/wordpress/2014/08/so-powerful-svg-smil-animation/


webgl


上述比较推荐文章:http://blog.csdn.net/zqjflash/article/details/44903859

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值