-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathjsparallax.min.js
5 lines (4 loc) · 2.62 KB
/
jsparallax.min.js
1
2
3
4
5
/*!
* GIT: https://github.com/shrekshrek/jstween
**/
!function(e,t){var i;"object"==typeof exports&&"undefined"!=typeof module?(i=require("jstween"),module.exports=t(i)):"function"==typeof define&&define.amd?define(["jstween"],t):e.JP=t(e.JT)}(this,function(h){"use strict";var s=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)},o=[],r=[],a=!1,l=0;function d(){var e=o.length;if(0===e)a=!1;else{var t=h.now(),i=t-l;l=t,500<i&&(i=33),r=o.slice(0);for(var n=0;n<e;n++)r[n]._update(i);s(d)}}const u=/(t|m|b|)(t|m|b|)(\+|-|)(\d+\.\d+|\d+|)(rem|px|%|vw|vh|)/i;function c(e,t){var i=document.scrollingElement.scrollTop,n=window.innerHeight,t=t.getBoundingClientRect(),s=0,o=u.exec(e),r=("t"==o[1]&&(s+=t.top+i),"m"==o[1]&&(s+=t.top+i+t.height/2),"b"==o[1]&&(s+=t.top+i+t.height),"t"==o[2]&&(s-=0),"m"==o[2]&&(s-=n/2),"b"==o[2]&&(s-=n),i=o[3]+o[4],Math.round(1e3*i)/1e3);switch(o[5]){case"rem":r*=h.getRem();break;case"vw":r*=h.getVw();break;case"vh":r*=h.getVh()}if(o[1]&&o[2])s-=r;else{if(o[1]||o[2])throw"from or to value error!!!";s+=r}return{origin:e,value:s}}function n(){this.initialize.apply(this,arguments)}return Object.assign(n.prototype,{initialize:function(e,t,i){for(var n in this.el=this.anchor="string"==typeof e?document.querySelector(e):e,i.anchor&&(this.anchor=document.querySelector(i.anchor),delete i.anchor),i.onInside&&(this.onInside=i.onInside,delete i.onInside),i.onOutside&&(this.onOutside=i.onOutside,delete i.onOutside),this.from=c(t.from,this.anchor),this.to=c(i.to,this.anchor),delete t.from,delete i.to,this.origin={},t)this.origin[n]=h.get(this.el,n);i.isPlaying=!1,this.tween=h.fromTo(e,1,t,i),this._update(),o.push(this),a||(l=h.now(),a=!0,s(d))},_reset(){for(var e in this.origin)h.set(this.el,this.origin[e]);this.from=c(this.from.origin,this.anchor),this.to=c(this.to.origin,this.anchor)},_update:function(){var e=document.scrollingElement.scrollTop;this.elapsed=(e-this.from.value)/(this.to.value-this.from.value),this.isInside=0<=this.elapsed&&this.elapsed<=1,this.isOutside=this.elapsed<0||1<this.elapsed,this.tween.seek(this.elapsed),this.isInside&&this.onInside&&this.onInside.apply(this,this.elapsed),this.isOutside&&this.onOutside&&this.onOutside.apply(this,this.elapsed),this.onUpdate&&this.onUpdate.apply(this,this.elapsed)},kill:function(){var e=o.indexOf(this);-1!==e&&o.splice(e,1),this.tween.kill(),this.el=this.anchor=this.origin=null}}),{create:function(e,t,i){return new n(e,t,i)},reset:function(){for(var e=o.length,t=0;t<e;t++)o[t]._reset()},kill:function(){for(var e=o.length-1;0<=e;e--)o[e].kill()}}});