讓div運(yùn)動起來 js實現(xiàn)緩動效果
更新時間:2017年07月06日 09:11:02 作者:風(fēng)雨后見彩虹
讓div運(yùn)動起來,這篇文章主要介紹了js實現(xiàn)緩動效果的相關(guān)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)緩動效果的具體代碼,供大家參考,具體內(nèi)容如下
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');
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解JavaScript基于面向?qū)ο笾畡?chuàng)建對象(1)
這篇文章主要介紹了JavaScript基于面向?qū)ο笾畡?chuàng)建對象,對創(chuàng)建對象進(jìn)行了詳細(xì)描述,感興趣的小伙伴們可以參考一下2015-12-12Bootstrap基本組件學(xué)習(xí)筆記之input輸入框組(9)
這篇文章主要為大家詳細(xì)介紹了Bootstrap基本組件學(xué)習(xí)筆記之input輸入框組,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12使用mouse事件實現(xiàn)簡單的鼠標(biāo)經(jīng)過特效
這篇文章主要介紹了使用mouse事件實現(xiàn)簡單的鼠標(biāo)經(jīng)過特效的方法,需要的朋友可以參考下2015-01-01echarts使用中關(guān)于y坐標(biāo)軸無法正常顯示的問題解決記錄
Echarts是由百度提供的數(shù)據(jù)可視化解決方案,下面這篇文章主要給大家介紹了關(guān)于echarts使用中關(guān)于y坐標(biāo)軸無法正常顯示的問題解決記錄,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12fix-ie5.js擴(kuò)展在IE5下不能使用的幾個方法
fix-ie5.js擴(kuò)展在IE5下不能使用的幾個方法...2007-08-08