国产探花免费观看_亚洲丰满少妇自慰呻吟_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');

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 拉萨市| 翼城县| 东莞市| 林西县| 会理县| 安康市| 陆川县| 浦北县| 南开区| 顺昌县| 区。| 乌兰县| 西乌珠穆沁旗| 秦皇岛市| 桐柏县| 南昌市| 宁阳县| 郓城县| 诏安县| 安泽县| 黄龙县| 陇西县| 达孜县| 石林| 永州市| 游戏| 西林县| 大理市| 合作市| 海淀区| 岳阳市| 江孜县| 屯昌县| 彝良县| 临江市| 元江| 体育| 巩留县| 青海省| 黄大仙区| 七台河市|