forked from alvarotrigo/fullPage.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.fullPage.min.js
29 lines (29 loc) · 10.9 KB
/
jquery.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
27
28
29
/**
* fullPage 1.3.1
* https://github.com/alvarotrigo/fullPage.js
* MIT licensed
*
* Copyright (C) 2013 alvarotrigo.com - A project by Alvaro Trigo
*/
(function(b){b.fn.fullpage=function(c){function v(a){if(c.autoScrolling){a=window.event||a;a=Math.max(-1,Math.min(1,a.wheelDelta||-a.detail));var e;e=b(".section.active");if(!k)if(e=e.find(".slides").length?e.find(".slide.active").find(".scrollable"):e.find(".scrollable"),0>a)if(0<e.length)if(p("bottom",e))b.fn.fullpage.moveSlideDown();else return!0;else b.fn.fullpage.moveSlideDown();else if(0<e.length)if(p("top",e))b.fn.fullpage.moveSlideUp();else return!0;else b.fn.fullpage.moveSlideUp();return!1}}
function n(a,e){var d={},f;f=a.position();var h=null!==f?f.top:null,w=D(a),l=a.data("anchor"),g=a.index(".section"),m=g;a.addClass("active").siblings().removeClass("active");k=!0;b.isFunction(e)||(location.hash="undefined"!==typeof l?l:"");c.autoScrolling?(d.top=-h,f="#superContainer"):(d.scrollTop=h,f="html, body");"up"===w&&(m+=2);c.css3&&c.autoScrolling?(b.isFunction(c.onLeave)&&c.onLeave.call(this,m,w),x("translate3d(0px, -"+h+"px, 0px)",!0),setTimeout(function(){b.isFunction(c.afterLoad)&&c.afterLoad.call(this,
l,g+1);setTimeout(function(){k=!1;b.isFunction(e)&&e.call(this)},E)},c.scrollingSpeed)):(b.isFunction(c.onLeave)&&c.onLeave.call(this,m,w),b(f).animate(d,c.scrollingSpeed,c.easing,function(){b.isFunction(c.afterLoad)&&c.afterLoad.call(this,l,g+1);setTimeout(function(){k=!1;b.isFunction(e)&&e.call(this)},E)}));y=l;c.autoScrolling&&(F(l),G(l,g))}function q(a,e){var d=e.position(),f=a.find(".slidesContainer").parent(),h=e.index(".slide"),g=a.closest(".section"),l=g.index(".section"),k=g.data("anchor"),
m=e.data("anchor");"undefined"===typeof m&&(m=h);g.hasClass("active")&&(c.loopBottom||g.find(".controlArrow.prev").toggle(0!=h),h?(location.hash=location.hash.split("/")[0]+"/"+m,c.loopBottom||g.find(".controlArrow.next").toggle(!e.is(":last-child"))):location.hash=location.hash.split("/")[0]);c.css3?(d="translate3d(-"+d.left+"px, 0px, 0px)",a.find(".slidesContainer").addClass("easing").css({"-webkit-transform":d,"-moz-transform":d,"-ms-transform":d,transform:d}),setTimeout(function(){b.isFunction(c.afterSlideLoad)&&
c.afterSlideLoad.call(this,k,l+1,m,h);r=!1},c.scrollingSpeed)):f.animate({scrollLeft:d.left},c.scrollingSpeed,function(){b.isFunction(c.afterSlideLoad)&&c.afterSlideLoad.call(this,k,l+1,m,h);r=!1})}function H(){var a=b(window).width(),e=b(window).height();c.resize&&N(e,a);b(".section").each(function(){var a=e-parseInt(b(this).css("padding-bottom"))-parseInt(b(this).css("padding-top"));c.scrollOverflow&&b(this).find(".scrollable").css("height",a+"px").parent().css("height",a+"px");c.verticalCentered&&
b(this).find(".tableCell").css("height",e+"px");b(this).css("height",e+"px");a=b(this).find(".slides");0<a.length&&q(a,a.find(".slide.active"))});b(".section.active").position();a=b(".section.active");a.index(".section")&&n(a)}function N(a,c){var d=825,f=a;825>a||900>c?(900>c&&(f=c,d=900),d=(100*f/d).toFixed(2),b("body").css("font-size",d+"%")):b("body").css("font-size","100%")}function G(a,e){c.navigation&&(b("#fullPage-nav").find(".active").removeClass("active"),a?b("#fullPage-nav").find('a[href="#'+
a+'"]').addClass("active"):b("#fullPage-nav").find("li").eq(e).find("a").addClass("active"))}function F(a){c.menu&&(b(c.menu).find(".active").removeClass("active"),b(c.menu).find('[data-menuanchor="'+a+'"]').addClass("active"))}function p(a,b){if("top"===a)return!b.scrollTop();if("bottom"===a)return b.scrollTop()+b.innerHeight()>=b[0].scrollHeight}function D(a){var c=b(".section.active").index(".section");a=a.index(".section");return c>a?"up":"down"}function I(a){a.css("overflow","hidden");var b=
a.closest(".section");a.get(0).scrollHeight-parseInt(b.css("padding-bottom"))-parseInt(b.css("padding-top"))>s&&(c.verticalCentered?a.find(".tableCell").wrapInner('<div class="scrollable" />'):a.wrapInner('<div class="scrollable" />'),b=s-parseInt(b.css("padding-bottom"))-parseInt(b.css("padding-top")),a.find(".scrollable").slimScroll({height:b+"px",size:"10px",alwaysVisible:!0}));a.css("overflow","")}function J(a){a.addClass("table").wrapInner('<div class="tableCell" style="height:'+s+'px;" />')}
function x(a,c){b("#superContainer").toggleClass("easing",c);b("#superContainer").css({"-webkit-transform":a,"-moz-transform":a,"-ms-transform":a,transform:a})}function K(a,c){var d=b('[data-anchor="'+a+'"]');n(d,function(){if("undefined"!=typeof c){var a=d.find(".slides"),b=a.find('[data-anchor="'+c+'"]');b.length||(b=a.find(".slide").eq(c));a.find(".slide").first().removeClass("active");q(a,b);b.addClass("active")}})}c=b.extend({verticalCentered:!0,resize:!0,slidesColor:[],anchors:[],scrollingSpeed:700,
easing:"easeInQuart",menu:!1,navigation:!1,navigationPosition:"right",navigationColor:"#000",controlArrowColor:"#fff",loopBottom:!1,loopTop:!1,loopHorizontal:!0,autoScrolling:!0,scrollOverflow:!1,css3:!1,paddingTop:null,paddingBottom:null,fixedElements:null,afterLoad:null,onLeave:null,afterRender:null,afterSlideLoad:null},c);var E=700;b.fn.fullpage.setAutoScrolling=function(a){c.autoScrolling=a;a=b(".section.active");c.autoScrolling?(b("html, body").css({overflow:"hidden",height:"100%"}),a.length&&
(c.css3?(a="translate3d(0px, -"+a.position().top+"px, 0px)",x(a,!1)):b("#superContainer").css("top","-"+a.position().top+"px"))):(b("html, body").css({overflow:"auto",height:"auto"}),c.css3?x("translate3d(0px, 0px, 0px)",!1):b("#superContainer").css("top","0px"),b("html, body").scrollTop(a.position().top))};var r=!1,z=navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|Windows Phone)/),s=b(window).height(),k=!1,y;document.addEventListener?(document.addEventListener("mousewheel",v,!1),
document.addEventListener("DOMMouseScroll",v,!1)):document.attachEvent("onmousewheel",v);b("body").wrapInner('<div id="superContainer" />');if(c.navigation){b("body").append('<div id="fullPage-nav"><ul></ul></div>');var g=b("#fullPage-nav");g.css("color",c.navigationColor);"right"===c.navigationPosition?g.css("right","17px"):g.css("left","17px")}b(".section").each(function(a){var e=b(this).find(".slide"),d=e.length;a||b(this).addClass("active");b(this).css("height",s+"px");c.paddingTop&&c.paddingBottom&&
b(this).css("padding",c.paddingTop+" 0 "+c.paddingBottom+" 0");"undefined"!==typeof c.slidesColor[a]&&b(this).css("background-color",c.slidesColor[a]);"undefined"!==typeof c.anchors[a]&&b(this).attr("data-anchor",c.anchors[a]);if(c.navigation){var f="";c.anchors.length&&(f=c.anchors[a]);g.find("ul").append('<li><a href="#'+f+'"><span></span></a></li>')}if(0<d){a=100*d;var h=100/d;e.wrapAll('<div class="slidesContainer" />');e.parent().wrap('<div class="slides" />');b(this).find(".slidesContainer").css("width",
a+"%");b(this).find(".slides").after('<div class="controlArrow prev"></div><div class="controlArrow next"></div>');b(this).find(".controlArrow.next").css("border-color","transparent transparent transparent "+c.controlArrowColor);b(this).find(".controlArrow.prev").css("border-color","transparent "+c.controlArrowColor+" transparent transparent");c.loopHorizontal||b(this).find(".controlArrow.prev").hide();e.each(function(a){a||b(this).addClass("active");b(this).css("width",h+"%");c.verticalCentered&&
J(b(this))})}else c.verticalCentered&&J(b(this))}).promise().done(function(){b.fn.fullpage.setAutoScrolling(c.autoScrolling);b.isFunction(c.afterRender)&&c.afterRender.call(this);c.fixedElements&&c.css3&&b(c.fixedElements).appendTo("body");c.navigation&&(g.css("margin-top","-"+g.height()/2+"px"),g.find("li").first().find("a").addClass("active"));c.menu&&c.css3&&b(c.menu).appendTo("body");if(c.scrollOverflow)b(window).on("load",function(){b(".section").each(function(){var a=b(this).find(".slide");
a.length?a.each(function(){I(b(this))}):I(b(this))})});b(window).on("load",function(){var a=window.location.hash.replace("#","").split("/"),b=a[0],a=a[1];b&&K(b,a)})});var L,A=!1;b(window).scroll(function(a){if(!c.autoScrolling){var e=b(window).scrollTop();a=b(".section").map(function(){if(b(this).offset().top<e+100)return b(this)});a=a[a.length-1];if(!a.hasClass("active")){A=!0;var d=D(a);b(".section.active").removeClass("active");a.addClass("active");var f=a.data("anchor");b.isFunction(c.onLeave)&&
c.onLeave.call(this,a.index(".section"),d);b.isFunction(c.afterLoad)&&c.afterLoad.call(this,f,a.index(".section")+1);F(f);G(f,0);c.anchors.length&&!k&&(y=f,location.hash=f);clearTimeout(L);L=setTimeout(function(){A=!1},100)}}});var B=0,t=0,C=0,u=0;b(document).on("touchmove",function(a){if(c.autoScrolling&&z&&(a.preventDefault(),a=a.originalEvent,!k))if(C=a.touches[0].pageY,u=a.touches[0].pageX,b(".section.active").find(".slides").length&&Math.abs(t-u)>Math.abs(B-C))t>u?b(".section.active").find(".controlArrow.next").trigger("click"):
t<u&&b(".section.active").find(".controlArrow.prev").trigger("click");else if(a=b(".section.active").find(".scrollable"),B>C)if(0<a.length)if(p("bottom",a))b.fn.fullpage.moveSlideDown();else return!0;else b.fn.fullpage.moveSlideDown();else if(0<a.length)if(p("top",a))b.fn.fullpage.moveSlideUp();else return!0;else b.fn.fullpage.moveSlideUp()});b(document).on("touchstart",function(a){c.autoScrolling&&z&&(a=a.originalEvent,B=a.touches[0].pageY,t=a.touches[0].pageX)});b.fn.fullpage.moveSlideUp=function(){var a=
b(".section.active").prev(".section");c.loopTop&&!a.length&&(a=b(".section").last());(0<a.length||!a.length&&c.loopTop)&&n(a)};b.fn.fullpage.moveSlideDown=function(){var a=b(".section.active").next(".section");c.loopBottom&&!a.length&&(a=b(".section").first());(0<a.length||!a.length&&c.loopBottom)&&n(a)};b.fn.fullpage.moveToSlide=function(a){var c="",c=isNaN(a)?b('[data-anchor="'+a+'"]'):b(".section").eq(a-1);0<c.length&&n(c)};b(window).on("hashchange",function(){if(!A){var a=window.location.hash.replace("#",
"").split("/"),b=a[0],a=a[1];b!==y&&K(b,a)}});b(document).keydown(function(a){if(!k)switch(a.which){case 38:case 33:b.fn.fullpage.moveSlideUp();break;case 40:case 34:b.fn.fullpage.moveSlideDown();break;case 37:b(".section.active").find(".controlArrow.prev").trigger("click");break;case 39:b(".section.active").find(".controlArrow.next").trigger("click")}});b(document).on("click","#fullPage-nav a",function(a){a.preventDefault();a=b(this).parent().index();n(b(".section").eq(a))});b(".section").on("click",
".controlArrow",function(){if(!r){r=!0;var a=b(this).closest(".section").find(".slides"),c=a.find(".slide.active"),d=null;c.removeClass("active");d=b(this).hasClass("prev")?c.prev(".slide"):c.next(".slide");d.length||(d=b(this).hasClass("prev")?c.siblings(":last"):c.siblings(":first"));q(a,d);d.addClass("active")}});b(".section").on("click",".toSlide",function(a){a.preventDefault();a=b(this).closest(".section").find(".slides");var c=a.find(".slide.active"),d=null,d=a.find(".slide").eq(b(this).data("index")-
1);0<d.length&&(c.removeClass("active"),q(a,d),d.addClass("active"))});if(!z){var M;b(window).resize(function(){clearTimeout(M);M=setTimeout(H,500)})}b(window).bind("orientationchange",function(){H()})}})(jQuery);