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