阅读背景:

类似于jQuery的动画效果

来源:互联网 

闲来无事,就写了个比较方便调用的动画效果

function skyAnimate(obj, options, step, callback) {
	if (!obj) return;
	var n = 0,
	timer = null,
	oStyle = [],
	de = [],
	c = [],
	b = 0;
	step = {
		'slow': 100,
		'normal': 50,
		'fast': 10
	} [step] || 64;
	var d = function(x) {
		return Math.sqrt(1 - Math.pow((x - 1), 2))
	}
	for (var i in options) {
		var obj_style = parseInt(sky_css(obj, i));
		if (!obj_style) obj_style = 0;
		de.push(obj_style) c.push(options[i] - obj_style);
		oStyle.push(i);
	}
	timer = setInterval(function() {
		if (n >= step) {
			clearInterval(timer);
			if (callback && callback instanceof Function) callback();
		}
		b = d(n / step);
		for (var j = 0,
		len = de.length; j < len; j++) {
			obj.style[oStyle[j]] = de[j] + c[j] * b + 'px';
		}
		n++;
	},
	15);
}
function sky_getType(o) {
	var t;
	return ((t = typeof(o)) == 'object' ? o == null && 'null' || (Object.prototype.toString.call(o)).slice(8, -1) : t).toLowerCase();
}
function sky_css(o, name) {
	if (sky_getType(name) == 'string') {
		if (o.style[name]) return o.style[name];
		if (o.currentStyle) return o.currentStyle[name];
		if (document.defaultView) return document.defaultView.getComputedStyle(o, "")[name];
	} else if (sky_getType(name) == 'object') {
		for (var i in name) {
			o.style[i] = name[i];
		}
	}
}
function skyAnim



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: