forked from alvarotrigo/fullPage.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fullPage.js
executable file
·1648 lines (1328 loc) · 48.3 KB
/
jquery.fullPage.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* fullPage 2.1.8
* https://github.com/alvarotrigo/fullPage.js
* MIT licensed
*
* Copyright (C) 2013 alvarotrigo.com - A project by Alvaro Trigo
*/
(function($) {
$.fn.fullpage = function(options) {
// Create some defaults, extending them with any options that were provided
options = $.extend({
"verticalCentered": true,
'resize': true,
'sectionsColor' : [],
'anchors':[],
'scrollingSpeed': 700,
'easing': 'easeInQuart',
'menu': false,
'navigation': false,
'navigationPosition': 'right',
'navigationColor': '#000',
'navigationTooltips': [],
'slidesNavigation': false,
'slidesNavPosition': 'bottom',
'controlArrowColor': '#fff',
'loopBottom': false,
'loopTop': false,
'loopHorizontal': true,
'autoScrolling': true,
'scrollOverflow': false,
'css3': false,
'paddingTop': 0,
'paddingBottom': 0,
'fixedElements': null,
'normalScrollElements': null,
'keyboardScrolling': true,
'touchSensitivity': 5,
'continuousVertical': false,
'animateAnchor': true,
'normalScrollElementTouchThreshold': 5,
'sectionSelector': '.section',
'slideSelector': '.slide',
//events
'afterLoad': null,
'onLeave': null,
'afterRender': null,
'afterResize': null,
'afterSlideLoad': null,
'onSlideLeave': null
}, options);
// Disable mutually exclusive settings
if (options.continuousVertical &&
(options.loopTop || options.loopBottom)) {
options.continuousVertical = false;
console && console.log && console.log("Option loopTop/loopBottom is mutually exclusive with continuousVertical; continuousVertical disabled");
}
//Defines the delay to take place before being able to scroll to the next section
//BE CAREFUL! Not recommened to change it under 400 for a good behavior in laptops and
//Apple devices (laptops, mouses...)
var scrollDelay = 600;
$.fn.fullpage.setAutoScrolling = function(value){
options.autoScrolling = value;
var element = $('.fp-section.active');
if(options.autoScrolling){
$('html, body').css({
'overflow' : 'hidden',
'height' : '100%'
});
if(element.length){
//moving the container up
silentScroll(element.position().top);
}
}else{
$('html, body').css({
'overflow' : 'auto',
'height' : 'auto'
});
silentScroll(0);
//scrolling the page to the section with no animation
$('html, body').scrollTop(element.position().top);
}
};
/**
* Defines the scrolling speed
*/
$.fn.fullpage.setScrollingSpeed = function(value){
options.scrollingSpeed = value;
};
/**
* Adds or remove the possiblity of scrolling through sections by using the mouse wheel or the trackpad.
*/
$.fn.fullpage.setMouseWheelScrolling = function (value){
if(value){
addMouseWheelHandler();
}else{
removeMouseWheelHandler();
}
};
/**
* Adds or remove the possiblity of scrolling through sections by using the mouse wheel/trackpad or touch gestures.
*/
$.fn.fullpage.setAllowScrolling = function (value){
if(value){
$.fn.fullpage.setMouseWheelScrolling(true);
addTouchHandler();
}else{
$.fn.fullpage.setMouseWheelScrolling(false);
removeTouchHandler();
}
};
/**
* Adds or remove the possiblity of scrolling through sections by using the keyboard arrow keys
*/
$.fn.fullpage.setKeyboardScrolling = function (value){
options.keyboardScrolling = value;
};
//flag to avoid very fast sliding for landscape sliders
var slideMoving = false;
var isTouchDevice = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|BB10|Windows Phone|Tizen|Bada)/);
var container = $(this);
var windowsHeight = $(window).height();
var isMoving = false;
var isResizing = false;
var lastScrolledDestiny;
var lastScrolledSlide;
var wrapperSelector = 'fullpage-wrapper';
$.fn.fullpage.setAllowScrolling(true);
//if css3 is not supported, it will use jQuery animations
if(options.css3){
options.css3 = support3d();
}
if($(this).length){
container.css({
'height': '100%',
'position': 'relative',
'-ms-touch-action': 'none'
});
//adding a class to recognize the container internally in the code
container.addClass(wrapperSelector);
}
//trying to use fullpage without a selector?
else{
console.error("Error! Fullpage.js needs to be initialized with a selector. For example: $('#myContainer').fullpage();");
}
//adding internal class names to void problem with common ones
$(options.sectionSelector).each(function(){
$(this).addClass('fp-section');
});
$(options.slideSelector).each(function(){
$(this).addClass('fp-slide');
});
//creating the navigation dots
if (options.navigation) {
$('body').append('<div id="fp-nav"><ul></ul></div>');
var nav = $('#fp-nav');
nav.css('color', options.navigationColor);
nav.addClass(options.navigationPosition);
}
$('.fp-section').each(function(index){
var that = $(this);
var slides = $(this).find('.fp-slide');
var numSlides = slides.length;
//if no active section is defined, the 1st one will be the default one
if(!index && $('.fp-section.active').length === 0) {
$(this).addClass('active');
}
$(this).css('height', windowsHeight + 'px');
if(options.paddingTop || options.paddingBottom){
$(this).css('padding', options.paddingTop + ' 0 ' + options.paddingBottom + ' 0');
}
if (typeof options.sectionsColor[index] !== 'undefined') {
$(this).css('background-color', options.sectionsColor[index]);
}
if (typeof options.anchors[index] !== 'undefined') {
$(this).attr('data-anchor', options.anchors[index]);
}
if (options.navigation) {
var link = '';
if(options.anchors.length){
link = options.anchors[index];
}
var tooltip = options.navigationTooltips[index];
if(typeof tooltip === 'undefined'){
tooltip = '';
}
nav.find('ul').append('<li data-tooltip="' + tooltip + '"><a href="#' + link + '"><span></span></a></li>');
}
// if there's any slide
if (numSlides > 1) {
var sliderWidth = numSlides * 100;
var slideWidth = 100 / numSlides;
slides.wrapAll('<div class="fp-slidesContainer" />');
slides.parent().wrap('<div class="fp-slides" />');
$(this).find('.fp-slidesContainer').css('width', sliderWidth + '%');
$(this).find('.fp-slides').after('<div class="fp-controlArrow fp-prev"></div><div class="fp-controlArrow fp-next"></div>');
if(options.controlArrowColor!='#fff'){
$(this).find('.fp-controlArrow.fp-next').css('border-color', 'transparent transparent transparent '+options.controlArrowColor);
$(this).find('.fp-controlArrow.fp-prev').css('border-color', 'transparent '+ options.controlArrowColor + ' transparent transparent');
}
if(!options.loopHorizontal){
$(this).find('.fp-controlArrow.fp-prev').hide();
}
if(options.slidesNavigation){
addSlidesNavigation($(this), numSlides);
}
slides.each(function(index) {
//if the slide won#t be an starting point, the default will be the first one
if(!index && that.find('.fp-slide.active').length == 0){
$(this).addClass('active');
}
$(this).css('width', slideWidth + '%');
if(options.verticalCentered){
addTableClass($(this));
}
});
}else{
if(options.verticalCentered){
addTableClass($(this));
}
}
}).promise().done(function(){
$.fn.fullpage.setAutoScrolling(options.autoScrolling);
//the starting point is a slide?
var activeSlide = $('.fp-section.active').find('.fp-slide.active');
if( activeSlide.length && ($('.fp-section.active').index('.fp-section') != 0 || ($('.fp-section.active').index('.fp-section') == 0 && activeSlide.index() != 0))){
var prevScrollingSpeepd = options.scrollingSpeed;
$.fn.fullpage.setScrollingSpeed (0);
landscapeScroll($('.fp-section.active').find('.fp-slides'), activeSlide);
$.fn.fullpage.setScrollingSpeed(prevScrollingSpeepd);
}
//fixed elements need to be moved out of the plugin container due to problems with CSS3.
if(options.fixedElements && options.css3){
$(options.fixedElements).appendTo('body');
}
//vertical centered of the navigation + first bullet active
if(options.navigation){
nav.css('margin-top', '-' + (nav.height()/2) + 'px');
nav.find('li').eq($('.fp-section.active').index('.fp-section')).find('a').addClass('active');
}
//moving the menu outside the main container if it is inside (avoid problems with fixed positions when using CSS3 tranforms)
if(options.menu && options.css3 && $(options.menu).closest('.fullpage-wrapper').length){
$(options.menu).appendTo('body');
}
if(options.scrollOverflow){
if(container.hasClass('fullpage-used')){
createSlimScrollingHandler();
}
//after DOM and images are loaded
$(window).on('load', createSlimScrollingHandler);
}else{
$.isFunction( options.afterRender ) && options.afterRender.call( this);
}
//getting the anchor link in the URL and deleting the `#`
var value = window.location.hash.replace('#', '').split('/');
var destiny = value[0];
if(destiny.length){
var section = $('[data-anchor="'+destiny+'"]');
if(!options.animateAnchor && section.length){
if(options.autoScrolling){
silentScroll(section.position().top);
}
else{
silentScroll(0);
//scrolling the page to the section with no animation
$('html, body').scrollTop(section.position().top);
}
activateMenuElement(destiny);
activateNavDots(destiny, null);
$.isFunction( options.afterLoad ) && options.afterLoad.call( this, destiny, (section.index('.fp-section') + 1));
//updating the active class
section.addClass('active').siblings().removeClass('active');
}
}
$(window).on('load', function() {
scrollToAnchor();
});
});
function createSlimScrollingHandler(){
$('.fp-section').each(function(){
var slides = $(this).find('.fp-slide');
if(slides.length){
slides.each(function(){
createSlimScrolling($(this));
});
}else{
createSlimScrolling($(this));
}
});
$.isFunction( options.afterRender ) && options.afterRender.call( this);
}
var scrollId;
var isScrolling = false;
//when scrolling...
$(window).on('scroll', scrollHandler);
function scrollHandler(){
if(!options.autoScrolling){
var currentScroll = $(window).scrollTop();
var scrolledSections = $('.fp-section').map(function(){
if ($(this).offset().top < (currentScroll + 100)){
return $(this);
}
});
//geting the last one, the current one on the screen
var currentSection = scrolledSections[scrolledSections.length-1];
//executing only once the first time we reach the section
if(!currentSection.hasClass('active')){
var leavingSection = $('.fp-section.active').index('.fp-section') + 1;
isScrolling = true;
var yMovement = getYmovement(currentSection);
currentSection.addClass('active').siblings().removeClass('active');
var anchorLink = currentSection.data('anchor');
$.isFunction( options.onLeave ) && options.onLeave.call( this, leavingSection, (currentSection.index('.fp-section') + 1), yMovement);
$.isFunction( options.afterLoad ) && options.afterLoad.call( this, anchorLink, (currentSection.index('.fp-section') + 1));
activateMenuElement(anchorLink);
activateNavDots(anchorLink, 0);
if(options.anchors.length && !isMoving){
//needed to enter in hashChange event when using the menu with anchor links
lastScrolledDestiny = anchorLink;
location.hash = anchorLink;
}
//small timeout in order to avoid entering in hashChange event when scrolling is not finished yet
clearTimeout(scrollId);
scrollId = setTimeout(function(){
isScrolling = false;
}, 100);
}
}
}
var touchStartY = 0;
var touchStartX = 0;
var touchEndY = 0;
var touchEndX = 0;
/* Detecting touch events
* As we are changing the top property of the page on scrolling, we can not use the traditional way to detect it.
* This way, the touchstart and the touch moves shows an small difference between them which is the
* used one to determine the direction.
*/
function touchMoveHandler(event){
var e = event.originalEvent;
if(options.autoScrolling){
//preventing the easing on iOS devices
event.preventDefault();
}
// additional: if one of the normalScrollElements isn't within options.normalScrollElementTouchThreshold hops up the DOM chain
if (!checkParentForNormalScrollElement(event.target)) {
var touchMoved = false;
var activeSection = $('.fp-section.active');
var scrollable;
if (!isMoving && !slideMoving) { //if theres any #
var touchEvents = getEventsPage(e);
touchEndY = touchEvents['y'];
touchEndX = touchEvents['x'];
//if movement in the X axys is greater than in the Y and the currect section has slides...
if (activeSection.find('.fp-slides').length && Math.abs(touchStartX - touchEndX) > (Math.abs(touchStartY - touchEndY))) {
//is the movement greater than the minimum resistance to scroll?
if (Math.abs(touchStartX - touchEndX) > ($(window).width() / 100 * options.touchSensitivity)) {
if (touchStartX > touchEndX) {
$.fn.fullpage.moveSlideRight(); //next
} else {
$.fn.fullpage.moveSlideLeft(); //prev
}
}
}
//vertical scrolling (only when autoScrolling is enabled)
else if(options.autoScrolling){
//if there are landscape slides, we check if the scrolling bar is in the current one or not
if(activeSection.find('.fp-slides').length){
scrollable= activeSection.find('.fp-slide.active').find('.fp-scrollable');
}else{
scrollable = activeSection.find('.fp-scrollable');
}
//is the movement greater than the minimum resistance to scroll?
if (Math.abs(touchStartY - touchEndY) > ($(window).height() / 100 * options.touchSensitivity)) {
if (touchStartY > touchEndY) {
if(scrollable.length > 0 ){
//is the scrollbar at the end of the scroll?
if(isScrolled('bottom', scrollable)){
$.fn.fullpage.moveSectionDown();
}else{
return true;
}
}else{
// moved down
$.fn.fullpage.moveSectionDown();
}
} else if (touchEndY > touchStartY) {
if(scrollable.length > 0){
//is the scrollbar at the start of the scroll?
if(isScrolled('top', scrollable)){
$.fn.fullpage.moveSectionUp();
}
else{
return true;
}
}else{
// moved up
$.fn.fullpage.moveSectionUp();
}
}
}
}
}
}
}
/**
* recursive function to loop up the parent nodes to check if one of them exists in options.normalScrollElements
* Currently works well for iOS - Android might need some testing
* @param {Element} el target element / jquery selector (in subsequent nodes)
* @param {int} hop current hop compared to options.normalScrollElementTouchThreshold
* @return {boolean} true if there is a match to options.normalScrollElements
*/
function checkParentForNormalScrollElement (el, hop) {
hop = hop || 0;
var parent = $(el).parent();
if (hop < options.normalScrollElementTouchThreshold &&
parent.is(options.normalScrollElements) ) {
return true;
} else if (hop == options.normalScrollElementTouchThreshold) {
return false;
} else {
return checkParentForNormalScrollElement(parent, ++hop);
}
}
function touchStartHandler(event){
var e = event.originalEvent;
var touchEvents = getEventsPage(e);
touchStartY = touchEvents['y'];
touchStartX = touchEvents['x'];
}
/**
* Detecting mousewheel scrolling
*
* http://blogs.sitepointstatic.com/examples/tech/mouse-wheel/index.html
* http://www.sitepoint.com/html5-javascript-mouse-wheel/
*/
function MouseWheelHandler(e) {
if(options.autoScrolling){
// cross-browser wheel delta
e = window.event || e;
var delta = Math.max(-1, Math.min(1,
(e.wheelDelta || -e.deltaY || -e.detail)));
var scrollable;
var activeSection = $('.fp-section.active');
if (!isMoving) { //if theres any #
//if there are landscape slides, we check if the scrolling bar is in the current one or not
if(activeSection.find('.fp-slides').length){
scrollable= activeSection.find('.fp-slide.active').find('.fp-scrollable');
}else{
scrollable = activeSection.find('.fp-scrollable');
}
//scrolling down?
if (delta < 0) {
if(scrollable.length > 0 ){
//is the scrollbar at the end of the scroll?
if(isScrolled('bottom', scrollable)){
$.fn.fullpage.moveSectionDown();
}else{
return true; //normal scroll
}
}else{
$.fn.fullpage.moveSectionDown();
}
}
//scrolling up?
else {
if(scrollable.length > 0){
//is the scrollbar at the start of the scroll?
if(isScrolled('top', scrollable)){
$.fn.fullpage.moveSectionUp();
}else{
return true; //normal scroll
}
}else{
$.fn.fullpage.moveSectionUp();
}
}
}
return false;
}
}
$.fn.fullpage.moveSectionUp = function(){
var prev = $('.fp-section.active').prev('.fp-section');
//looping to the bottom if there's no more sections above
if (!prev.length && (options.loopTop || options.continuousVertical)) {
prev = $('.fp-section').last();
}
if (prev.length) {
scrollPage(prev, null, true);
}
};
$.fn.fullpage.moveSectionDown = function (){
var next = $('.fp-section.active').next('.fp-section');
//looping to the top if there's no more sections below
if(!next.length &&
(options.loopBottom || options.continuousVertical)){
next = $('.fp-section').first();
}
if(next.length > 0 ||
(!next.length &&
(options.loopBottom || options.continuousVertical))){
scrollPage(next, null, false);
}
};
$.fn.fullpage.moveTo = function (section, slide){
var destiny = '';
if(isNaN(section)){
destiny = $('[data-anchor="'+section+'"]');
}else{
destiny = $('.fp-section').eq( (section -1) );
}
if (typeof slide !== 'undefined'){
scrollPageAndSlide(section, slide);
}else if(destiny.length > 0){
scrollPage(destiny);
}
};
$.fn.fullpage.moveSlideRight = function(){
moveSlide('next');
};
$.fn.fullpage.moveSlideLeft = function(){
moveSlide('prev');
};
function moveSlide(direction){
var activeSection = $('.fp-section.active');
var slides = activeSection.find('.fp-slides');
// more than one slide needed and nothing should be sliding
if (!slides.length || slideMoving) {
return;
}
var currentSlide = slides.find('.fp-slide.active');
var destiny = null;
if(direction === 'prev'){
destiny = currentSlide.prev('.fp-slide');
}else{
destiny = currentSlide.next('.fp-slide');
}
//isn't there a next slide in the secuence?
if(!destiny.length){
//respect loopHorizontal settin
if (!options.loopHorizontal) return;
if(direction === 'prev'){
destiny = currentSlide.siblings(':last');
}else{
destiny = currentSlide.siblings(':first');
}
}
slideMoving = true;
landscapeScroll(slides, destiny);
}
function scrollPage(element, callback, isMovementUp){
var scrollOptions = {}, scrolledElement;
var dest = element.position();
if(typeof dest === "undefined"){ return; } //there's no element to scroll, leaving the function
var dtop = dest.top;
var yMovement = getYmovement(element);
var anchorLink = element.data('anchor');
var sectionIndex = element.index('.fp-section');
var activeSlide = element.find('.fp-slide.active');
var activeSection = $('.fp-section.active');
var leavingSection = activeSection.index('.fp-section') + 1;
//caching the value of isResizing at the momment the function is called
//because it will be checked later inside a setTimeout and the value might change
var localIsResizing = isResizing;
if(activeSlide.length){
var slideAnchorLink = activeSlide.data('anchor');
var slideIndex = activeSlide.index();
}
// If continuousVertical && we need to wrap around
if (options.autoScrolling && options.continuousVertical && typeof (isMovementUp) !== "undefined" &&
((!isMovementUp && yMovement == 'up') || // Intending to scroll down but about to go up or
(isMovementUp && yMovement == 'down'))) { // intending to scroll up but about to go down
// Scrolling down
if (!isMovementUp) {
// Move all previous sections to after the active section
$(".fp-section.active").after(activeSection.prevAll(".fp-section").get().reverse());
}
else { // Scrolling up
// Move all next sections to before the active section
$(".fp-section.active").before(activeSection.nextAll(".fp-section"));
}
// Maintain the displayed position (now that we changed the element order)
silentScroll($('.fp-section.active').position().top);
// save for later the elements that still need to be reordered
var wrapAroundElements = activeSection;
// Recalculate animation variables
dest = element.position();
dtop = dest.top;
yMovement = getYmovement(element);
}
element.addClass('active').siblings().removeClass('active');
//preventing from activating the MouseWheelHandler event
//more than once if the page is scrolling
isMoving = true;
if(typeof anchorLink !== 'undefined'){
setURLHash(slideIndex, slideAnchorLink, anchorLink);
}
if(options.autoScrolling){
scrollOptions['top'] = -dtop;
scrolledElement = '.'+wrapperSelector;
}else{
scrollOptions['scrollTop'] = dtop;
scrolledElement = 'html, body';
}
// Fix section order after continuousVertical changes have been animated
var continuousVerticalFixSectionOrder = function () {
// If continuousVertical is in effect (and autoScrolling would also be in effect then),
// finish moving the elements around so the direct navigation will function more simply
if (!wrapAroundElements || !wrapAroundElements.length) {
return;
}
if (isMovementUp) {
$('.fp-section:first').before(wrapAroundElements);
}
else {
$('.fp-section:last').after(wrapAroundElements);
}
silentScroll($('.fp-section.active').position().top);
};
// Use CSS3 translate functionality or...
if (options.css3 && options.autoScrolling) {
//callback (onLeave) if the site is not just resizing and readjusting the slides
$.isFunction(options.onLeave) && !localIsResizing && options.onLeave.call(this, leavingSection, (sectionIndex + 1), yMovement);
var translate3d = 'translate3d(0px, -' + dtop + 'px, 0px)';
transformContainer(translate3d, true);
setTimeout(function () {
//fix section order from continuousVertical
continuousVerticalFixSectionOrder();
//callback (afterLoad) if the site is not just resizing and readjusting the slides
$.isFunction(options.afterLoad) && !localIsResizing && options.afterLoad.call(this, anchorLink, (sectionIndex + 1));
setTimeout(function () {
isMoving = false;
$.isFunction(callback) && callback.call(this);
}, scrollDelay);
}, options.scrollingSpeed);
} else { // ... use jQuery animate
//callback (onLeave) if the site is not just resizing and readjusting the slides
$.isFunction(options.onLeave) && !localIsResizing && options.onLeave.call(this, leavingSection, (sectionIndex + 1), yMovement);
$(scrolledElement).animate(
scrollOptions
, options.scrollingSpeed, options.easing, function () {
//fix section order from continuousVertical
continuousVerticalFixSectionOrder();
//callback (afterLoad) if the site is not just resizing and readjusting the slides
$.isFunction(options.afterLoad) && !localIsResizing && options.afterLoad.call(this, anchorLink, (sectionIndex + 1));
setTimeout(function () {
isMoving = false;
$.isFunction(callback) && callback.call(this);
}, scrollDelay);
});
}
//flag to avoid callingn `scrollPage()` twice in case of using anchor links
lastScrolledDestiny = anchorLink;
//avoid firing it twice (as it does also on scroll)
if(options.autoScrolling){
activateMenuElement(anchorLink);
activateNavDots(anchorLink, sectionIndex);
}
}
function scrollToAnchor(){
//getting the anchor link in the URL and deleting the `#`
var value = window.location.hash.replace('#', '').split('/');
var section = value[0];
var slide = value[1];
if(section){ //if theres any #
scrollPageAndSlide(section, slide);
}
}
//detecting any change on the URL to scroll to the given anchor link
//(a way to detect back history button as we play with the hashes on the URL)
$(window).on('hashchange', hashChangeHandler);
function hashChangeHandler(){
if(!isScrolling){
var value = window.location.hash.replace('#', '').split('/');
var section = value[0];
var slide = value[1];
if(section.length){
//when moving to a slide in the first section for the first time (first time to add an anchor to the URL)
var isFirstSlideMove = (typeof lastScrolledDestiny === 'undefined');
var isFirstScrollMove = (typeof lastScrolledDestiny === 'undefined' && typeof slide === 'undefined' && !slideMoving);
/*in order to call scrollpage() only once for each destination at a time
It is called twice for each scroll otherwise, as in case of using anchorlinks `hashChange`
event is fired on every scroll too.*/
if ((section && section !== lastScrolledDestiny) && !isFirstSlideMove || isFirstScrollMove || (!slideMoving && lastScrolledSlide != slide )) {
scrollPageAndSlide(section, slide);
}
}
}
}
/**
* Sliding with arrow keys, both, vertical and horizontal
*/
$(document).keydown(function(e) {
//Moving the main page with the keyboard arrows if keyboard scrolling is enabled
if (options.keyboardScrolling && !isMoving) {
switch (e.which) {
//up
case 38:
case 33:
$.fn.fullpage.moveSectionUp();
break;
//down
case 40:
case 34:
$.fn.fullpage.moveSectionDown();
break;
//Home
case 36:
$.fn.fullpage.moveTo(1);
break;
//End
case 35:
$.fn.fullpage.moveTo( $('.fp-section').length );
break;
//left
case 37:
$.fn.fullpage.moveSlideLeft();
break;
//right
case 39:
$.fn.fullpage.moveSlideRight();
break;
default:
return; // exit this handler for other keys
}
}
});
//navigation action
$(document).on('click', '#fp-nav a', function(e){
e.preventDefault();
var index = $(this).parent().index();
scrollPage($('.fp-section').eq(index));
});
//navigation tooltips
$(document).on({
mouseenter: function(){
var tooltip = $(this).data('tooltip');
$('<div class="fp-tooltip ' + options.navigationPosition +'">' + tooltip + '</div>').hide().appendTo($(this)).fadeIn(200);
},
mouseleave: function(){
$(this).find('.fp-tooltip').fadeOut().remove();
}
}, '#fp-nav li');
if(options.normalScrollElements){
$(document).on('mouseover', options.normalScrollElements, function () {
$.fn.fullpage.setMouseWheelScrolling(false);
});
$(document).on('mouseout', options.normalScrollElements, function(){
$.fn.fullpage.setMouseWheelScrolling(true);
});
}
/**
* Scrolling horizontally when clicking on the slider controls.
*/
$('.fp-section').on('click', '.fp-controlArrow', function() {
if ($(this).hasClass('fp-prev')) {
$.fn.fullpage.moveSlideLeft();
} else {
$.fn.fullpage.moveSlideRight();
}
});
/**
* Scrolling horizontally when clicking on the slider controls.
*/
$('.fp-section').on('click', '.toSlide', function(e) {
e.preventDefault();
var slides = $(this).closest('.fp-section').find('.fp-slides');
var currentSlide = slides.find('.fp-slide.active');
var destiny = null;
destiny = slides.find('.fp-slide').eq( ($(this).data('index') -1) );
if(destiny.length > 0){
landscapeScroll(slides, destiny);
}
});
/**
* Scrolls horizontal sliders.
*/
function landscapeScroll(slides, destiny){
var destinyPos = destiny.position();
var slidesContainer = slides.find('.fp-slidesContainer').parent();
var slideIndex = destiny.index();
var section = slides.closest('.fp-section');
var sectionIndex = section.index('.fp-section');
var anchorLink = section.data('anchor');
var slidesNav = section.find('.fp-slidesNav');
var slideAnchor = destiny.data('anchor');
//caching the value of isResizing at the momment the function is called
//because it will be checked later inside a setTimeout and the value might change
var localIsResizing = isResizing;
if(options.onSlideLeave){
var prevSlideIndex = section.find('.fp-slide.active').index();
var xMovement = getXmovement(prevSlideIndex, slideIndex);
//if the site is not just resizing and readjusting the slides
if(!localIsResizing){
$.isFunction( options.onSlideLeave ) && options.onSlideLeave.call( this, anchorLink, (sectionIndex + 1), prevSlideIndex, xMovement);
}
}
destiny.addClass('active').siblings().removeClass('active');
if(typeof slideAnchor === 'undefined'){
slideAnchor = slideIndex;
}
//only changing the URL if the slides are in the current section (not for resize re-adjusting)
if(section.hasClass('active')){
if(!options.loopHorizontal){
//hidding it for the fist slide, showing for the rest