Skip to content

Commit

Permalink
Fix scrolling issues in Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
shyam-habarakada committed Aug 29, 2013
1 parent d1b944b commit b01b084
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
39 changes: 35 additions & 4 deletions vlv.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@ function jsvlv(width,height,contentSource,delegate) {
requestAnimationFrame(scroll);
}

function onmousewheelMozilla(e) {
var dy = e.wheelDeltaY || e.wheelDelta || -(e.detail);
e.preventDefault();
if(_frozen) { return; }
e.stopPropagation();
removeKeyboardFocus();
// mozilla sends smaller dy values. use a multiplier to amplify the value
// _scrollDistancePending += (dy * ( Math.abs(dy) > 1 ? dy * dy : 1));
_scrollDistancePending += -dy;
console.log(dy);
requestAnimationFrame(scroll);
}

function bindMousewheel() {
if(typeof(document.onmousewheel) == "object") {
document.body.addEventListener("mousewheel", onmousewheel);
} else {
// For firefox http://bit.ly/1037qm5
document.addEventListener("DOMMouseScroll", onmousewheelMozilla);
}
}

function unbindMousewheel() {
if(typeof(document.onmousewheel) == "object") {
document.body.removeEventListener("mousewheel", onmousewheel);
} else {
// For firefox http://bit.ly/1037qm5
document.removeEventListener("DOMMouseScroll", onmousewheelMozilla);
}
}

function onmouseenter(e) {
if(!_frozen) {
_scrollbar.enable();
Expand Down Expand Up @@ -306,7 +337,7 @@ function jsvlv(width,height,contentSource,delegate) {
_el.appendChild(_scrollbar.getElement());
_$el.bind("mouseenter", onmouseenter);
_$el.bind("mouseleave", onmouseleave);
_el.addEventListener("mousewheel", onmousewheel, true);
bindMousewheel();
document.addEventListener("keydown", onkeydown, true);
container.appendChild(_el);
_showing = true;
Expand All @@ -316,9 +347,9 @@ function jsvlv(width,height,contentSource,delegate) {
}

_i.hide = function() {
_$el.bind("mouseenter", onmouseenter);
_$el.bind("mouseleave", onmouseleave);
_el.removeEventListener("mousewheel", onmousewheel, true);
_$el.unbind("mouseenter", onmouseenter);
_$el.unbind("mouseleave", onmouseleave);
unbindMousewheel();
document.removeEventListener("keydown", onkeydown, true);
if(_showing) {
_container && _container.removeChild(_el);
Expand Down
2 changes: 1 addition & 1 deletion vlv.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b01b084

Please sign in to comment.