色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

javascript簡(jiǎn)易動(dòng)畫類(div漸變)

程序源碼
復(fù)制代碼 代碼如下:
function Animate(el, prop, opts) {
this.el = el;
this.prop = prop;
this.from = opts.from;
this.to = opts.to;
this.time = opts.time;
this.callback = opts.callback;
this.animDiff = this.to - this.from;
}

Animate.prototype._setStyle = function(val) {
switch(this.prop) {
case 'opacity':
this.el.style[this.prop] = val;
this.el.style.filter = 'alpha(opacity=' + val * 100 + ')';
break;
default:
this.el.style[this.prop] = val + 'px';
break;
}
}

Animate.prototype._animate = function() {
var that = this;
this.now = new Date();
this.diff = this.now - this.startTime;

if (this.diff > this.time) {
this._setStyle(this.to);

if (this.callback) {
this.callback.call(this);
}
clearInterval(this.timer);
return;
}

this.percentage = (Math.floor((this.diff / this.time) * 100) / 100);
this.val = (this.animDiff * this.percentage) + this.from;
this._setStyle(this.val);
}

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;
}();

使用方法
復(fù)制代碼 代碼如下:
// 透明度漸變
function changeOpacity() {
// 透明度漸變 從1 - 0 漸變時(shí)間1000ms
var fx = 'opacity', from = 1, to = 0, time = 1000;
// 漸變完畢執(zhí)行的回調(diào)函數(shù)
var callback = function() {
from = 0; to = 1;
new Animate(demo, fx, { from: from, to: to, time: time, callback: resetButton}).start();
}
// 實(shí)例化漸變函數(shù)
new Animate(demo, fx, {
from: from,
to: to,
time: time,
callback: callback
}).start();
}

演示代碼:

[Ctrl+A 全選 注:如需引入外部Js需刷新才能執(zhí)行]

JavaScript技術(shù)javascript簡(jiǎn)易動(dòng)畫類(div漸變),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 磴口县| 方城县| 静宁县| 抚宁县| 华坪县| 兴仁县| 富顺县| 郯城县| 广西| 施秉县| 大洼县| 峨眉山市| 扎兰屯市| 黔西县| 绥德县| 凤凰县| 辰溪县| 石城县| 太康县| 聊城市| 黑龙江省| 灵宝市| 安徽省| 泽州县| 乌恰县| 西平县| 静海县| 蕉岭县| 新安县| 三原县| 阿巴嘎旗| 栾川县| 宣汉县| 盐池县| 湖口县| 团风县| 沙洋县| 砚山县| 山阴县| 柞水县| 资兴市|