forked from shrekshrek/jstween
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsparallax.min.js
5 lines (4 loc) · 2.5 KB
/
jsparallax.min.js
1
2
3
4
5
/*!
* GIT: https://github.com/shrekshrek/jstween
**/
!function(t,i){if("object"==typeof exports&&"undefined"!=typeof module){var s=require("jstween");module.exports=i(s)}else"function"==typeof define&&define.amd?define(["jstween"],i):t.JP=i(t.JT)}(this,function(t){"use strict";function i(){this.initialize.apply(this,arguments)}return Object.assign(i.prototype,{initialize:function(t){t=t||{},this.el=t.el,this.hook=t.hook||0,this.key=t.key||"y",this.pin=0,this.isSeek=!1,this.curPos=this.prevPos=null,this.tweens=[],this.calls=[],this.pins=[]},update:function(t){this.prevPos=this.curPos,this.curPos=this.prevPos+t||0,this._checkTween(),this._checkCall(),this._checkPin(),this.el&&(this.el[this.key]=-(this.curPos-this.pin))},addCall:function(t,i){this.calls.push({start:i,call:t}),this._updateEndTime()},_checkCall:function(){for(var t=0,i=this.calls.length;t<i;t++){var s=this.calls[t],e=this.prevPos+this.hook-s.start,n=this.curPos+this.hook-s.start;!this.isSeek&&(0===s.start&&0===e&&n>0||e<s.start&&n>=s.start||e>s.start&&n<=s.start||s.start===this.endTime&&e===this.endTime&&n<this.endTime)&&s.call()}},addTween:function(i,s,e){i.stop();var n=t.get(i.el,this.key),h=n-s;this.tweens.push({start:h,tween:i,duration:e})},_checkTween:function(){for(var t=0,i=this.tweens.length;t<i;t++){var s=this.tweens[t],e=this.prevPos+this.hook-s.start,n=this.curPos+this.hook-s.start;0===s.duration?!this.isSeek&&(0===s.start&&0===e&&n>0||e<s.start&&n>=s.start||e>s.start&&n<=s.start||s.start===this.endTime&&e===this.endTime&&n<this.endTime)&&s.play(0):s.tween.seek(n/s.duration*s.tween.endTime/1e3,this.isSeek)}},addPin:function(t,i){this.pins.push({start:t,duration:i})},_checkPin:function(){this.pin=0;for(var t=0,i=this.pins.length;t<i;t++){var s=this.pins[t],e=this.curPos+this.hook-s.start;e>s.duration?this.pin+=s.duration:e>0&&(this.pin+=e)}},fromTo:function(i,s,e,n,h,o){var r=t.fromTo(i,s,e,n);return this.addTween(r,h,o),this},from:function(i,s,e,n,h){var o=t.from(i,s,e);return this.addTween(o,n,h),this},to:function(i,s,e,n,h){var o=t.to(i,s,e);return this.addTween(o,n,h),this},add:function(t,i,s){switch(typeof t){case"object":this.addTween(t,i,s);break;case"function":this.addCall(t,i);break;case"number":this.addPin(t,i);break;default:throw"add action is wrong!!!"}return this},seek:function(t,i){this.curPos!==t&&(void 0!==i&&(this.isSeek=i),this.update(t-this.curPos),this.isSeek=!1)},kill:function(){this.tweens=[],this.calls=[],this.pins=[],this.curPos=this.prevPos=null}}),{create:function(t){return new i(t)},kill:function(t){t.kill()}}});