未實(shí)現(xiàn)的功能:無法實(shí)現(xiàn)單位換算,不能實(shí)現(xiàn)顏色漸變(還有很多,有待完善...)

代碼中的使用方法如下: 復(fù)制代碼 代碼如下: var $m = $M("divAnimate");

_("btnAnimate").onclick = " /> 一本久道视频一本久道,一级大片免费观看,成人免费视频a

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

一個簡單的js動畫效果代碼

實(shí)現(xiàn)的功能:移動,暫停,恢復(fù),停止.

未實(shí)現(xiàn)的功能:無法實(shí)現(xiàn)單位換算,不能實(shí)現(xiàn)顏色漸變(還有很多,有待完善...)

代碼中的使用方法如下:
復(fù)制代碼 代碼如下:
var $m = $M("divAnimate");

_("btnAnimate").onclick = function(){
this.disabled = true;
var that = this;
$m.animate({left:"300px",top:"100px",width:"300px", height:"200px",opacity:0.3},{duration:5000,easing:Tween.Back.easeInOut}).delay(200)
.animate({left:"50px",top:"300px",width:"150px",height:"100px",opacity:0.8},{duration:2000,easing:Tween.Elastic.easeInOut,
callback:function(){
that.disabled = false;
}
});
}
_("btnPause").onclick = function(){
$m.pause();
this.disabled = true;
_("btnResume").disabled = false;
}
_("btnResume").disabled = true;
_("btnResume").onclick = function(){
$m.resume();
this.disabled = true;
_("btnPause").disabled = false;
}

_("btnStop").onclick = function(){
$m.stop();
_("btnAnimate").disabled = false;
}


功能實(shí)現(xiàn):
復(fù)制代碼 代碼如下:
/* 簡單動畫方法
* 未實(shí)現(xiàn)單位換算
*/
var $M = function(obj){
var elem = ("string" === typeof obj )?document.getElementById(obj):obj;
var _this = {},props = {},timeId,isBusy = false,isPause = false;
var queue = [],_current;
//直線運(yùn)動算法
function Linear(t,b,c,d){ return c*t/d + b;}
function setCss(className,value){
if(className == "opacity"){
if(document.defaultView){
elem.style["opacity"] = value;
} else {
elem.style["filter"] = 'alpha(opacity=' + 100 * value + ')';
}
} else {
elem.style[className] = value;
}
}
function getCss(className){
if(className == "opacity"){
var ret = "";
if(document.defaultView){
ret = document.defaultView.getComputedStyle(elem,null)['opacity'] || 1;
} else {
ret = elem.currentStyle['filter']?(elem.currentStyle['filter'].match(/^alpha/(opacity=([/d/.]+)/)$/))[1]/100 : 1;
}
return ret.toString();
} else {
return elem.style[className].toString();
}
}

function _move(params,easing,st,ht,callback){
var t = ((new Date()).getTime() - st);
_current.t = t;
if(isPause){return;}
easing = easing||Linear;
ht = ht || 500;
for(var p in params){
if(!props[p]){
var iv = parseFloat(getCss(p)) || 0;
var ev = parseFloat(params[p]);
props[p] = {
iv:iv,
iu:iv?getCss(p).substring(iv.toString().length):null,
ev:ev,
eu:params[p].toString().substring(ev.toString().length)
}
//TODO(初始值的單位和目標(biāo)值的單位不相同需要處理)
}
if(t >= ht){t = ht;}
var nv = easing(t,props[p].iv,(props[p].ev - props[p].iv),ht);
nv = parseFloat(nv);
setCss(p,nv + props[p].eu);
}

if(t < ht){
timeId = setTimeout(function(){
_move(params,easing,st,ht,callback);
},13);
} else {
props = {};
isBusy = false;
if(callback){
callback();
}
run();
}
}
function run(){
if(!isBusy && queue.length != 0){
var o = queue.shift();
var _delay = 0;
while(o && o.delay){
_delay += o.delay;
o = queue.shift();
}
if(o){
_current = o;
isBusy = true;
setTimeout(function(){
var st = (new Date()).getTime();
_move(o.params,o.options.easing,st,o.options.duration,o.options.callback);
},_delay);
}
}
}

var _this = {
animate:function(params,options){
queue.push({params:params,options:options});
isPause = false;
run();
return _this;
},
delay:function(ms){
queue.push({delay:ms});
return _this;
},
pause:function(){
isPause = true;
return _this;
},
resume:function(){
if(_current){
var o = _current;
isPause = false;
var st = (new Date()).getTime() - _current.t;
_move(o.params,o.options.easing,st,o.options.duration,o.options.callback);
return _this;
}
},
stop:function(){
isPause = true;
isBusy = false;
queue = [];
props = {};
return _this;
}
};
return _this;
}

參考地址:
http://www.jb51.NET/article/24309.htm

JavaScript技術(shù)一個簡單的js動畫效果代碼,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: free hd xxxx moms movie777| 古铜| 进宝| 美国禁忌1984| 香水有毒微电影无删减完整版| 鲁迅电影| 黄色网址在线免费播放| 林智妍三级全部电影| 刚满18岁| 辽宁卫视在线观看| 六年级上册美术教案人教版| 陈程玉| 小霸王解说呐| 长谷川清| 淡蓝色的雨简谱| 闺蜜心窍 电影| 周超个人资料简介| 张志忠演员| g83钻孔循环怎么编程| 极寒复出| 极品少妇啪啪久久蜜臀| 雪中悍刀行第一季演员表| 性文章| 人流后吃什么| 楼下的房客到底讲的什么| 小孩打屁股针视频| 实时| 妖猫传票房| 我的m属性学姐| 黄视频在线播放| 朱迅身高| 陕西卫视节目表| 睡衣派对| 黄电影在线观看| 杨硕| 刘德华歌| 座头市 电影| 太上老君说五斗金章受生经| 日本大片网站| 洪金宝电影| 上香香灰打卷图解|