JS函数动画(透明度淡入淡出)封装

function easeMove(obj,attr,iTarget,speedScale,time){
				clearInterval(obj.timer)
				obj.timer=setInterval(function(){
					var attrValue=getStyle(oAll,attr)*100;
					var speedEnd = (iTarget - attrValue) / speedScale;
					speedEnd=speedEnd>0?Math.ceil(speedEnd):Math.floor(speedEnd);
					//console.log("计算速度值:"+speedEnd);
					var isStop = true;
					if(iTarget!=attrValue){
						isStop=false;
						obj.style[attr]=(attrValue+speedEnd)/100;
					}if(isStop){
							clearInterval(obj.timer);		
						}
					console.log("attrValue:"+ obj.style[attr]);
				},time);
			}

//获得CSS样式属性值:

function getStyle(obj,attr){
			if(obj.currentStyle){
					//支持IE
					return obj.currentStyle[attr];
				}else{
					return getComputedStyle(obj)[attr];
				}
			}

猜你喜欢

转载自blog.csdn.net/weixin_39200549/article/details/82959203
今日推荐