|
185 | 185 |
|
186 | 186 | //geting the last one
|
187 | 187 | var currentSection = scrolledSections[scrolledSections.length-1];
|
188 |
| - |
| 188 | + var yMovement = getYmovement(currentSection); |
| 189 | + |
189 | 190 | if(!currentSection.hasClass('active')){
|
190 | 191 | $('.section.active').removeClass('active');
|
191 | 192 | currentSection.addClass('active');
|
192 | 193 |
|
193 | 194 | 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); |
195 | 196 |
|
196 | 197 | $.isFunction( options.afterLoad ) && options.afterLoad.call( this, anchorLink, (currentSection.index('.section') + 1));
|
197 | 198 |
|
|
335 | 336 | }
|
336 | 337 |
|
337 | 338 | if (prev.length > 0 || (!prev.length && options.loopTop)){
|
338 |
| - prev.addClass('active').siblings().removeClass('active'); |
339 | 339 | scrollPage(prev);
|
340 | 340 | }
|
341 | 341 | };
|
|
349 | 349 | }
|
350 | 350 |
|
351 | 351 | if (next.length > 0 || (!next.length && options.loopBottom)){
|
352 |
| - next.addClass('active').siblings().removeClass('active'); |
353 | 352 | scrollPage(next);
|
354 | 353 | }
|
355 | 354 | };
|
|
364 | 363 | }
|
365 | 364 |
|
366 | 365 | if (destiny.length > 0) {
|
367 |
| - destiny.addClass('active').siblings().removeClass('active'); |
368 | 366 | scrollPage(destiny);
|
369 | 367 | }
|
370 | 368 | };
|
371 |
| - |
| 369 | + |
372 | 370 | function scrollPage(element) {
|
373 | 371 | var scrollOptions = {}, scrolledElement;
|
374 | 372 | var dest = element.position();
|
375 | 373 | var dtop = dest !== null ? dest.top : null;
|
| 374 | + var yMovement = getYmovement(element); |
376 | 375 |
|
| 376 | + element.addClass('active').siblings().removeClass('active'); |
| 377 | + |
377 | 378 | //preventing from activating the MouseWheelHandler event
|
378 | 379 | //more than once if the page is scrolling
|
379 | 380 | isMoving = true;
|
|
406 | 407 | isMoving = false;
|
407 | 408 | }, 700);
|
408 | 409 | }else{
|
409 |
| - $.isFunction( options.onLeave ) && options.onLeave.call( this, (element.index('.section'))); |
| 410 | + $.isFunction( options.onLeave ) && options.onLeave.call( this, element.index('.section'), yMovement); |
410 | 411 |
|
411 | 412 | $(scrolledElement).animate(
|
412 | 413 | scrollOptions
|
|
420 | 421 | });
|
421 | 422 | }
|
422 | 423 |
|
423 |
| - |
424 |
| - |
425 | 424 | //flag to avoid callingn `scrollPage()` twice in case of using anchor links
|
426 | 425 | lastScrolledDestiny = anchorLink;
|
427 | 426 |
|
|
437 | 436 |
|
438 | 437 | var element = $('[data-anchor="'+value+'"]');
|
439 | 438 |
|
440 |
| - element.addClass('active').siblings().removeClass('active'); |
441 | 439 | //updating the array positions...
|
442 | 440 | scrollPage(element);
|
443 | 441 | }
|
|
454 | 452 | if (value !== lastScrolledDestiny) {
|
455 | 453 | var element = $('[data-anchor="'+value+'"]');
|
456 | 454 |
|
457 |
| - element.addClass('active').siblings().removeClass('active'); |
458 | 455 | scrollPage(element);
|
459 | 456 | }
|
460 | 457 | });
|
|
714 | 711 | }
|
715 | 712 | }
|
716 | 713 |
|
| 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 | + |
717 | 725 | };
|
718 | 726 | })(jQuery);
|
0 commit comments