-
Notifications
You must be signed in to change notification settings - Fork 25
/
overscroll.min.js
1 lines (1 loc) · 1.13 KB
/
overscroll.min.js
1
function getSupportedTransform(){var e="transform WebkitTransform MozTransform OTransform msTransform".split(" ");for(var t=0;t<e.length;t++){if(document.createElement("div").style[e[t]]!==undefined){return e[t]}}return false}function Overscroll(){var e=0;var t=0;var n=document.body;var r=window;var i=getSupportedTransform();var s={top:[],bottom:[]};this.init=function(){this.window=window;this.onScroll();this.onResize();this.scrollEvent=this.window.addEventListener("scroll",this.onScroll);this.resizeEvent=this.window.addEventListener("resize",this.onResize)};this.bindElement=function(e,t,n){n=n||1;t=t||"top";if(s.top.length===0&&s.bottom.length===0){this.init()}var r={domElement:e,height:e.clientHeight,delta:n};s[t].push(r)};this.onScroll=function(){e=r.pageYOffset||n.scrollTop;o()};this.onResize=function(){t=r.innerHeight};var o=function(){var n;if(e<=0){for(n=0;n<s.top.length;n++){var r=s.top[n];var o=-e*r.delta;if(o>r.height){o=r.height}r.domElement.style[i]="translateY("+o+"px )"}}else if(e>=t){for(n=0;n<s.bottom.length;n++){var r=s.bottom[n];var o=(e-t)*r.delta;if(o>r.height){o=r.height}r.domElement.style[i]="translateY("+ -o+"px )"}}}}