forked from powy1993/fullpage
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathfullPage.min.js
26 lines (25 loc) · 9.12 KB
/
fullPage.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
* Chriswang
* 396276123@qq.com
* 2014.12.8
* Github:https://github.com/powy1993/fullpage
*/
function FullPage(k){function C(a,c,b,g){this.cx=3*a;this.bx=3*(b-a)-this.cx;this.ax=1-this.cx-this.bx;this.cy=3*c;this.by=3*(g-c)-this.cy;this.ay=1-this.cy-this.by}var D=document.getElementById(k.id),d=D.children,z=d.length,V=z,E=k.slideTime||800,x=k.effect||{},f=0,A,F,h,s,m,G,O,P,Q,H=[],R=[],S,t,T=null,u=!1,J=!1,W,l,B,I,w,X,Y,q,v,y,L,U;if(d&&1!==z){k.mode&&(J=-1!==k.mode.indexOf("nav:"),R=k.mode.split(","),S=R.length);for(l=0;l<z;l++)H.push(d[l].style);A=!!window.addEventListener;F="ontouchstart"in
window||window.DocumentTouch&&document instanceof DocumentTouch;(function(){var a=navigator.userAgent,c=a.indexOf("Android"),b;B=-1!==a.indexOf("QQBrowser")?200:0;-1!==c&&(b=a.substring(c+7,c+11).replace(" ",""));return b||0})();h=function(a){switch(!0){case ""===a.webkitTransition:return"webkit";case ""===a.MozTransition:return"Moz";case ""===a.msTransition:return"ms";case ""===a.OTransition:return"O";default:return""}}(document.createElement("Chriswang").style);C.prototype={epsilon:1E-5,sampleCurveX:function(a){return((this.ax*
a+this.bx)*a+this.cx)*a},sampleCurveY:function(a){return((this.ay*a+this.by)*a+this.cy)*a},sampleCurveDerivativeX:function(a){return(3*this.ax*a+2*this.bx)*a+this.cx},solveCurveX:function(a,c){var b,g,e,d;e=a;for(g=0;8>g;g++){d=this.sampleCurveX(e)-a;if(Math.abs(d)<c)return e;b=this.sampleCurveDerivativeX(e);if(Math.abs(b)<c)break;e-=d/b}b=0;g=1;e=a;if(e<b)return b;if(e>g)return g;for(;b<g;){d=this.sampleCurveX(e);if(Math.abs(d-a)<c)break;a>d?b=e:g=e;e=.5*(g-b)+b}return e},solve:function(a,c){return this.sampleCurveY(this.solveCurveX(a,
c))}};I=function(){s=document.documentElement.clientWidth||window.innerWidth;m=document.documentElement.clientHeight||window.innerHeight;D.style.height=m+"px"};l=function(a,c,b,g){G=a;O=c;P=b;Q=g};if("string"===typeof k.easing)switch(k.easing){case "ease":l(.25,.1,.25,1);break;case "linear":l(0,0,1,1);break;case "ease-in":l(.42,0,1,1);break;case "ease-out":l(0,0,.58,1);break;case "ease-in-out":l(.42,0,.58,1)}else l(k.easing[0],k.easing[1],k.easing[2],k.easing[3]);if(""!==h){for(;V--;)H[V][h+"TransitionTimingFunction"]=
"cubic-bezier("+G+","+O+","+P+","+Q+")";w=function(a,c,b,g,e){a=a.style;c="translate("+c+"px,"+b+"px) translateZ(0)";e.scale&&(c+=0===g?" scale("+e.scale[0]+")":" scale("+e.scale[1]+")");e.rotate&&(c+=0===g?" rotate("+e.rotate[0]+"deg)":" rotate("+e.rotate[1]+"deg)");a[h+"TransformOrigin"]="50% 50%";a[h+"Transform"]=c}}else W=new C(G,O,P,Q),w=function(a,c,b,g){var e=a.currentStyle,d=a.style,f=parseInt(d.left||e.left,10),h=parseInt(d.top||e.top,10),k=c-f,q=b-h,l=+new Date+g,m=0,r=x.opacity,s;clearInterval(T);
T=setInterval(function(){var a;+new Date>l?(a=r?"left:"+c+"px;top:"+b+"px;filter:alpha(opacity="+100*r[1]+");":"left:"+c+"px;top:"+b+"px;",clearInterval(T)):(s=l-new Date,m=s/g,m=W.solve(1-m,C.prototype.epsilon),a="left:"+(f+k*m)+"px;top:"+(h+q*m)+"px;",r&&(a+="filter:alpha(opacity="+100*(r[1]*m-r[0]*(1-m))+");"));d.cssText=a},13)};X={transform:function(a,c,b){var g=0,e=""!==h||"none"!==a.translate&&a.translate?B:-50;switch(a.translate){case "Y":g=b>c?m:-m;w(d[b],0,g,0,a);break;case "X":g=b>c?s:-s;
w(d[b],g,0,0,a);break;case "XY":g={X:b>c?s:-s,Y:b>c?m:-m};w(d[b],g.X,g.Y,0,a);break;default:w(d[b],0,0,0,a)}setTimeout(function(){w(d[b],0,0,E,a)},e+50)},opacity:function(a,c,b){var g=d[b].style;g.opacity=a[0];setTimeout(function(){g.opacity=a[1]},70)}};Y=A&&F?navigator.userAgent.indexOf("Firefox")?function(a,c){a.addEventListener("click",c,!1)}:function(a,c,b){a.addEventListener("touchstart",c,!1);b&&a.addEventListener("touchmove",function(a){a.preventDefault()},!1)}:function(a,c){a.onclick=c};q=
function(a,c,b){var d=a.className,e=[];if(-1!==d.indexOf(c)){e=d.split(" ");for(d=e.length;d--;)e[d]===c&&(" "===b||""===b?e.splice(d,1):e[d]=b);e.length?a.className=e.join(" "):(a.removeAttribute("class"),a.removeAttribute("className"))}};J&&(L=function(a,c){var d=t[c].className;q(t[a],"active"," ");t[c].className=""===d?"active":d+" active"});k.continuous&&(v=function(a){return(z+a%z)%z});y=function(a){var c=B,b,g;if(!u&&a!==f){if(k.continuous)a=v(a);else if(a>=z||0>a)return;u=!0;for(g in x)X[g](x[g],
f,a);c+=""===h?20:0;b=f;f=a;J&&L(b,f);setTimeout(function(){d[a].className+=" slide"},c);setTimeout(function(){H[a][h+"TransitionDuration"]=E+"ms"},20);setTimeout(function(){q(d[b],"current","");q(d[f],"slide","current");k.callback&&k.callback(f,d[f]);u=!1},E+B+120)}};I();l=d[f].className;d[f].className=-1!==l.indexOf("current")?l:l+" current";for(A?window.addEventListener("resize",I,!1):window.onresize=I;S--;)(function(a){switch(!0){case "wheel"===a:U=function(a){a=a||window.event;a.preventDefault?
a.preventDefault():a.returnValue=!1;u||(a=-a.wheelDelta||a.detail,y(f+(0>a?-1:1)))};A&&document.addEventListener("DOMMouseScroll",U,!1);window.onmousewheel=document.onmousewheel=U;break;case "touch"===a:if(!F||!A)break;(function(){var a=x.transform.scale[0],b=x.transform.scale[1]-a,g=x.transform.rotate[0],e=x.transform.rotate[1]-g,l=x.opacity[0],t=x.opacity[1]-l,w,y,A,B,I,r={},C=!1,n,p,F,M,N,G,K;"Y"===x.transform.translate?(F=function(){var a=f-1,b=f+1;k.continuous&&(a=v(a),b=v(b));n=H[a];p=H[b];
n&&(n[h+"TransitionDuration"]="0ms",n[h+"Transform"]="translate(0,-"+m+"px) translateZ(0)",n[h+"TransformOrigin"]="50% 100%",d[a].className+=" swipe");p&&(p[h+"TransitionDuration"]="0ms",p[h+"Transform"]="translate(0,"+m+"px) translateZ(0)",p[h+"TransformOrigin"]="50% 0%",d[b].className+=" swipe")},G=function(d){var f=Math.abs(d.y/m),Z=" scale("+(a+b*f)+") rotate("+(g+e*f)+"deg)";n&&0<d.y&&(n.opacity=l+t*f,n[h+"Transform"]="translate(0,"+(d.y-m)+"px) translateZ(0)"+Z);p&&0>d.y&&(p.opacity=l+t*f,p[h+
"Transform"]="translate(0,"+(m+d.y)+"px) translateZ(0)"+Z)},M=function(a,b){var c=E>>1,e=f+b;k.continuous&&(e=v(e));q(d[e],"swipe","slide");a.opacity=1;a[h+"TransitionDuration"]=c+"ms";a[h+"Transform"]="translate(0,"+b*m+"px) translateZ(0)";setTimeout(function(){q(d[e],"slide","");setTimeout(function(){u=!1},50)},c)},N=function(a,b){var c=f+b,e=~~(E/1.5),g,l;k.continuous?(c=v(c),g=d[v(f-b)],l=!0):g=d[f-b];g&&q(g,"swipe","");!l&&0>c||c>z-1?setTimeout(function(){u=!1},50):(J&&L(f,c),a.opacity=1,q(d[c],
"swipe","slide"),a[h+"TransitionDuration"]=e+"ms",a[h+"Transform"]="translate(0,0) translateZ(0)",setTimeout(function(){q(d[f],"current","");q(d[c],"slide","current");f=c;k.callback&&k.callback(f,d[f]);setTimeout(function(){u=!1},50)},e))}):(F=function(){var a=f-1,b=f+1;k.continuous&&(a=v(a),b=v(b));n=H[a];p=H[b];n&&(n[h+"TransitionDuration"]="0ms",n[h+"Transform"]="translate(-"+s+"px,0) translateZ(0)",n[h+"TransformOrigin"]="100% 50%",d[a].className+=" swipe");p&&(p[h+"TransitionDuration"]="0ms",
p[h+"Transform"]="translate("+s+"px,0) translateZ(0)",p[h+"TransformOrigin"]="0 50%",d[b].className+=" swipe")},G=function(d){var f=Math.abs(d.x/s),k=" scale("+(a+b*f)+") rotate("+(g+e*f)+"deg)";n&&0<d.x&&(console.log(),n.opacity=l+t*f,n[h+"Transform"]="translate("+(d.x-s)+"px,0) translateZ(0)"+k);p&&0>d.x&&(p.opacity=l+t*f,p[h+"Transform"]="translate("+(s+d.x)+"px,0) translateZ(0)"+k)},M=function(a,b){var c=E>>1,e=f+b;k.continuous&&(e=v(e));q(d[e],"swipe","slide");a.opacity=1;a[h+"TransitionDuration"]=
c+"ms";a[h+"Transform"]="translate("+b*s+"px,0) translateZ(0)";setTimeout(function(){q(d[e],"slide","");setTimeout(function(){u=!1},50)},c)},N=function(a,b){var c=f+b,e=~~(E/1.5),g,l;k.continuous?(c=v(c),g=d[v(f-b)],l=!0):g=d[f-b];g&&q(g,"swipe","");!l&&0>c||c>z-1?setTimeout(function(){u=!1},50):(J&&L(f,c),q(d[c],"swipe","slide"),a.opacity=1,a[h+"TransitionDuration"]=e+"ms",a[h+"Transform"]="translate(0,0) translateZ(0)",setTimeout(function(){q(d[f],"current","");q(d[c],"slide","current");f=c;k.callback&&
k.callback(f,d[f]);setTimeout(function(){u=!1},50)},e))});w=function(a){var b=a.touches[0];a.preventDefault();1<event.touches.length||event.scale&&1!==event.scale||(r={x:b.pageX-A,y:b.pageY-B},C?K&&G(r):(K=Math.abs(r.x)>Math.abs(r.y)?"X":"Y",K=K===k.effect.transform.translate?!0:!1,C=!0))};y=function(a){var b=a.changedTouches[0];a=+new Date-I;var c;c=0;var d=!1;r={x:b.pageX-A,y:b.pageY-B};b=Math.abs(r.x);c=Math.abs(r.y);switch(k.effect.transform.translate){case "Y":d=250>+a&&30<c||c>.3*m;c=0<r.y?
-1:1;break;case "X":d=250>+a&&30<b||b>.3*s;c=0<r.x?-1:1;break;default:d=350>+a&&50<c+b||c>.3*m||b>.3*s,c=b>c?0<r.x?-1:1:0<r.y?-1:1}d&&K?-1===c?N(n,-1):N(p,1):(n&&M(n,-1),p&&M(p,1));D.removeEventListener("touchmove",w,!1);D.removeEventListener("touchend",y,!1)};D.addEventListener("touchstart",function(a){a=a.touches[0];u||(u=!0,A=a.pageX,B=a.pageY,I=+new Date,r={},C=!1,F(),D.addEventListener("touchmove",w,!1),D.addEventListener("touchend",y,!1))},!1)})();break;case -1!==a.indexOf("nav:"):(function(){var c=
a.split(":")[1],c=document.getElementById(c),b,d;t=c.children;b=t.length;d=t[f].className;if(c&&t){for(;b--;)t[b].setAttribute("data-page",b);-1===d.indexOf("active")&&(t[f].className=""===d?"active":d+" active");b=function(a){var b;a=a||window.event;a=a.target||a.srcElement;for(b=a.tagName.toLowerCase();"li"!==b;){if("ul"===b)return;a=a.parentNode;b=a.tagName.toLowerCase()}y(+a.getAttribute("data-page"))};Y(c,b,1)}})()}})(R[S]);return{thisPage:function(){return f},go:function(a){y(a)},next:function(){y(f+
1)},prev:function(){y(f-1)}}}};