Skip to content

Commit

Permalink
Iteration on mouse wheel delta normalization, ref #91 #87 #67
Browse files Browse the repository at this point in the history
  • Loading branch information
darsain committed Oct 10, 2013
1 parent c185dcd commit 0c4d251
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/sly.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
var clickEvent = 'click.' + namespace;
var mouseDownEvent = 'mousedown.' + namespace;
var tmpArray = [];
var time;

/**
* Sly.
Expand Down Expand Up @@ -100,6 +101,11 @@
var dragging = {
released: 1
};
var scrolling = {
last: 0,
delta: 0,
resetTime: 200
};
var renderID = 0;
var historyID = 0;
var cycleID = 0;
Expand Down Expand Up @@ -620,6 +626,9 @@
* @return {Void}
*/
self.slideBy = function (delta, immediate) {
if (!delta) {
return;
}
if (itemNav) {
self[centeredNav ? 'toCenter' : 'toStart'](
within((centeredNav ? rel.centerItem : rel.firstItem) + o.scrollBy * delta, 0, items.length)
Expand Down Expand Up @@ -1494,7 +1503,23 @@
*/
function normalizeWheelDelta(event) {
// event.deltaY needed only for compatibility with jQuery mousewheel plugin in FF & IE
return within(-event.wheelDelta || event.detail || event.deltaY, -1, 1);
scrolling.curDelta = event.wheelDelta ? -event.wheelDelta / 120 : (event.detail || event.deltaY) / 3;
if (!itemNav) {
return scrolling.curDelta;
}
time = +new Date();
if (scrolling.last < time - scrolling.resetTime) {
scrolling.delta = 0;
}
scrolling.last = time;
scrolling.delta += scrolling.curDelta;
if (Math.abs(scrolling.delta) < 1) {
scrolling.finalDelta = 0;
} else {
scrolling.finalDelta = Math.round(scrolling.delta / 1);
scrolling.delta %= 1;
}
return scrolling.finalDelta;
}

/**
Expand Down

0 comments on commit 0c4d251

Please sign in to comment.