国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

讓div運動起來 js實現緩動效果

2019-11-19 16:09:21
字體:
來源:轉載
供稿:網友

本文實例為大家分享了js實現緩動效果的具體代碼,供大家參考,具體內容如下

var tween = {  linear:function(t,b,c,d){    return c*t/d + b;  },  easeIn:function(t,b,c,d){    return c * ( t /= d ) * t + b;  },  strongEaseIn:function(t,b,c,d){    return c * ( t /= d ) * t * t * t * t + b;  },  strongEaseOut:function(t,b,c,d){    return c * ( ( t = t / d -1 ) * t * t * t * t +1 ) + b;  },  sineaseIn:function(t,b,c,d){    return c * ( t /= d ) * t * t + b;    },  sineaseOut:function(t,b,c,d){    return c * ( ( t = t / d -1 ) * t * t *t +1 ) + b;  }};var Animate = function(dom){  this.dom = dom;  this.startTime = 0;  this.startPos = 0;  this.endPos = 0;  this.propertyName = null;  this.easing = null;  this.duration = null;}Animate.prototype.start = function(propertyName,endPos,duration,easing){  this.startTime = +new Date;  this.startPos = this.dom.getBoundingClientRect()[propertyName];  this.propertyName = propertyName;  this.endPos = endPos;  this.duration = duration;  this.easing = tween[easing];  var self = this;  var timeId = setInterval(function(){    if(self.step() === false){      clearInterval(timeId);    }  },19);}Animate.prototype.step = function(){  var t = +new Date;  if(t>=this.startTime + this.duration){    this.update(this.endPos);    return false;  }  var pos = this.easing(t-this.startTime, this.startPos, this.endPos - this.startPos, this.duration);  this.update(pos);}Animate.prototype.update = function(pos){  this.dom.style[this.propertyName] = pos + 'px';}var div = document.getElementById('div');var animate = new Animate(div);animate.start('left',500,1000,'strongEaseOut');

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新丰县| 青铜峡市| 祥云县| 广安市| 鹤峰县| 马关县| 赤水市| 南澳县| 灯塔市| 墨玉县| 武川县| 长治市| 神木县| 龙口市| 芒康县| 榆社县| 平度市| 宣化县| 湖口县| 沅江市| 博罗县| 兴义市| 平塘县| 长丰县| 临沂市| 镇雄县| 紫阳县| 新野县| 安丘市| 新建县| 南充市| 禄丰县| 崇文区| 信宜市| 合江县| 革吉县| 合山市| 英超| 肃宁县| 辉南县| 工布江达县|