Skip to content

Commit a000a31

Browse files
committed
- Improved onLeave feature detecting the direction of the movement.
- Optimized code added on `scrollPage` function.
1 parent 49c9114 commit a000a31

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

jquery.fullPage.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,14 @@
185185

186186
//geting the last one
187187
var currentSection = scrolledSections[scrolledSections.length-1];
188-
188+
var yMovement = getYmovement(currentSection);
189+
189190
if(!currentSection.hasClass('active')){
190191
$('.section.active').removeClass('active');
191192
currentSection.addClass('active');
192193

193194
var anchorLink = currentSection.attr('data-anchor');
194-
$.isFunction( options.onLeave ) && options.onLeave.call( this, (currentSection.index('.section')));
195+
$.isFunction( options.onLeave ) && options.onLeave.call( this, currentSection.index('.section'), yMovement);
195196

196197
$.isFunction( options.afterLoad ) && options.afterLoad.call( this, anchorLink, (currentSection.index('.section') + 1));
197198

@@ -335,7 +336,6 @@
335336
}
336337

337338
if (prev.length > 0 || (!prev.length && options.loopTop)){
338-
prev.addClass('active').siblings().removeClass('active');
339339
scrollPage(prev);
340340
}
341341
};
@@ -349,7 +349,6 @@
349349
}
350350

351351
if (next.length > 0 || (!next.length && options.loopBottom)){
352-
next.addClass('active').siblings().removeClass('active');
353352
scrollPage(next);
354353
}
355354
};
@@ -364,16 +363,18 @@
364363
}
365364

366365
if (destiny.length > 0) {
367-
destiny.addClass('active').siblings().removeClass('active');
368366
scrollPage(destiny);
369367
}
370368
};
371-
369+
372370
function scrollPage(element) {
373371
var scrollOptions = {}, scrolledElement;
374372
var dest = element.position();
375373
var dtop = dest !== null ? dest.top : null;
374+
var yMovement = getYmovement(element);
376375

376+
element.addClass('active').siblings().removeClass('active');
377+
377378
//preventing from activating the MouseWheelHandler event
378379
//more than once if the page is scrolling
379380
isMoving = true;
@@ -406,7 +407,7 @@
406407
isMoving = false;
407408
}, 700);
408409
}else{
409-
$.isFunction( options.onLeave ) && options.onLeave.call( this, (element.index('.section')));
410+
$.isFunction( options.onLeave ) && options.onLeave.call( this, element.index('.section'), yMovement);
410411

411412
$(scrolledElement).animate(
412413
scrollOptions
@@ -420,8 +421,6 @@
420421
});
421422
}
422423

423-
424-
425424
//flag to avoid callingn `scrollPage()` twice in case of using anchor links
426425
lastScrolledDestiny = anchorLink;
427426

@@ -437,7 +436,6 @@
437436

438437
var element = $('[data-anchor="'+value+'"]');
439438

440-
element.addClass('active').siblings().removeClass('active');
441439
//updating the array positions...
442440
scrollPage(element);
443441
}
@@ -454,7 +452,6 @@
454452
if (value !== lastScrolledDestiny) {
455453
var element = $('[data-anchor="'+value+'"]');
456454

457-
element.addClass('active').siblings().removeClass('active');
458455
scrollPage(element);
459456
}
460457
});
@@ -714,5 +711,16 @@
714711
}
715712
}
716713

714+
715+
function getYmovement(destiny){
716+
var fromIndex = $('.section.active').index('.section');
717+
var toIndex = destiny.index('.section');
718+
719+
if(fromIndex > toIndex){
720+
return 'up';
721+
}
722+
return 'down';
723+
}
724+
717725
};
718726
})(jQuery);

0 commit comments

Comments
 (0)