Animate.prototype.start = function() {
var that = this;
this.startTime = new Date();
clearInterval(this.timer);
this.timer = setInterval(function() {
that._animate.call(that);
}, 4);
}
Animate.canTransition = function() {
var el = document.createElement('foo');
el.style.cssText = '-webkit-transition: all .5s linear;';
return !!el.style.webkitTransitionProperty;
}();
window.onload = function() {
var T$ = function(id) { return document.getElementById(id); }
var T$$ = function(n) { return document.getElementsByName(n); }
var demo = T$('demo'); var btns = T$$('fx');
function disableButton() {
for (var i = 0, len = btns.length; i < len; ++i) {
btns[i].disabled = 'disabled';
}
}
function resetButton() {
for (var i = 0, len = btns.length; i < len; ++i) {
btns[i].disabled = '';
}
}
// 宽度渐变
function changeWidth() {
var fx = 'width', from = demo.clientWidth, to = from - 270, time = 1000;
var callback = function() {
from = demo.clientWidth; to = from + 270;
new Animate(demo, fx, { from: from, to: to, time: time, callback: resetButton }).start();
}
new Animate(demo, fx, {
from: from,
to: to,
time: time,
callback: callback
}).start();
}
// 高度渐变
function changeHeight() {
var fx = 'height', from = demo.clientHeight, to = from + 100, time = 1000;
var callback = function() {
from = demo.clientHeight; to = from - 100;
new Animate(demo, fx, { from: from, to: to, time: time, callback: resetButton}).start();
}
new Animate(demo, fx, {
from: from,
to: to,
time: time,
callback: callback
}).start();
}
// 透明度渐变
function changeOpacity() {
var fx = 'opacity', from = 1, to = 0, time = 1000;
var callback = function() {
from = 0; to = 1;
new Animate(demo, fx, { from: from, to: to, time: time, callback: resetButton}).start();
}
new Animate(demo, fx, {
from: from,
to: to,
time: time,
callback: callback
}).start();
}
// 边框渐变
function changeBorderWidth() {
var fx = 'borderWidth', from = 2, to = 10, time = 1000;
var callback = function() {
from = 10; to = 2;
new Animate(demo, fx, { from: from, to: to, time: time, callback: resetButton }).start();
}
new Animate(demo, fx, {
from: from,
to: to,
time: time,
callback: callback
}).start();
}