Skip to content

Commit ee55946

Browse files
committed
- Updating version number to create new release
1 parent 22ea76e commit ee55946

10 files changed

+72
-24
lines changed

dist/jquery.pagepiling.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* pagepiling.js 1.5.3
2+
* pagepiling.js 1.5.4
33
*
44
* https://github.com/alvarotrigo/pagePiling.js
55
* @license MIT licensed

dist/jquery.pagepiling.js

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* pagepiling.js 1.5.3
2+
* pagepiling.js 1.5.4
33
*
44
* https://github.com/alvarotrigo/pagePiling.js
55
* @license MIT licensed
@@ -16,6 +16,7 @@
1616
var lastAnimation = 0;
1717
var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints));
1818
var touchStartY = 0, touchStartX = 0, touchEndY = 0, touchEndX = 0;
19+
var scrollings = [];
1920

2021
//Defines the delay to take place before being able to scroll to the next section
2122
//BE CAREFUL! Not recommened to change it under 400 for a good behavior in laptops and
@@ -558,30 +559,77 @@
558559
* http://blogs.sitepointstatic.com/examples/tech/mouse-wheel/index.html
559560
* http://www.sitepoint.com/html5-javascript-mouse-wheel/
560561
*/
562+
var prevTime = new Date().getTime();
563+
561564
function MouseWheelHandler(e) {
562-
if(!isMoving()){
563-
// cross-browser wheel delta
564-
e = window.event || e;
565-
var delta = Math.max(-1, Math.min(1,
566-
(e.wheelDelta || -e.deltaY || -e.detail)));
565+
var curTime = new Date().getTime();
566+
567+
// cross-browser wheel delta
568+
e = e || window.event;
569+
var value = e.wheelDelta || -e.deltaY || -e.detail;
570+
var delta = Math.max(-1, Math.min(1, value));
571+
572+
var horizontalDetection = typeof e.wheelDeltaX !== 'undefined' || typeof e.deltaX !== 'undefined';
573+
var isScrollingVertically = (Math.abs(e.wheelDeltaX) < Math.abs(e.wheelDelta)) || (Math.abs(e.deltaX ) < Math.abs(e.deltaY) || !horizontalDetection);
574+
575+
//Limiting the array to 150 (lets not waste memory!)
576+
if(scrollings.length > 149){
577+
scrollings.shift();
578+
}
579+
580+
//keeping record of the previous scrollings
581+
scrollings.push(Math.abs(value));
582+
583+
//time difference between the last scroll and the current one
584+
var timeDiff = curTime-prevTime;
585+
prevTime = curTime;
586+
587+
//haven't they scrolled in a while?
588+
//(enough to be consider a different scrolling action to scroll another section)
589+
if(timeDiff > 200){
590+
//emptying the array, we dont care about old scrollings for our averages
591+
scrollings = [];
592+
}
567593

594+
if(!isMoving()){
568595
var activeSection = $('.pp-section.active');
569596
var scrollable = isScrollable(activeSection);
570597

571-
//scrolling down?
572-
if (delta < 0) {
573-
scrolling('down', scrollable);
598+
var averageEnd = getAverage(scrollings, 10);
599+
var averageMiddle = getAverage(scrollings, 70);
600+
var isAccelerating = averageEnd >= averageMiddle;
574601

575-
//scrolling up?
576-
}else {
577-
scrolling('up', scrollable);
578-
}
602+
if(isAccelerating && isScrollingVertically){
603+
//scrolling down?
604+
if (delta < 0) {
605+
scrolling('down', scrollable);
579606

607+
//scrolling up?
608+
}else if(delta>0){
609+
scrolling('up', scrollable);
610+
}
611+
}
580612

581613
return false;
582614
}
583615
}
584616

617+
/**
618+
* Gets the average of the last `number` elements of the given array.
619+
*/
620+
function getAverage(elements, number){
621+
var sum = 0;
622+
623+
//taking `number` elements from the end to make the average, if there are not enought, 1
624+
var lastElements = elements.slice(Math.max(elements.length - number, 1));
625+
626+
for(var i = 0; i < lastElements.length; i++){
627+
sum = sum + lastElements[i];
628+
}
629+
630+
return Math.ceil(sum/number);
631+
}
632+
585633
/**
586634
* Determines the way of scrolling up or down:
587635
* by 'automatically' scrolling a section or by using the default and normal scrolling.
@@ -606,7 +654,7 @@
606654
return true;
607655
}
608656
}else{
609-
// moved up/down
657+
//moved up/down
610658
scrollSection();
611659
}
612660
}

dist/jquery.pagepiling.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.pagepiling.min.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)