0

how is it possible catch the "mousewheel" event on a body with an hidden overflow?

I have already tried this but it doesn't work on my case.

Community
  • 1
  • 1
Marco C
  • 3,101
  • 3
  • 30
  • 49

1 Answers1

0

You can use jQuery mousewheel plugin.

EDIT: Here is the code from my plugin:

var self = this;
var scroll_object;

if (!navigator.userAgent.toLowerCase().match(/(webkit)[ \/]([\w.]+)/) &&
    self[0].tagName.toLowerCase() == 'body') {
    scroll_object = $('html');
} else {
    scroll_object = self;
}
...
self = $.extend(self, {
    scroll: function(amount) {
        var pos;
        amount = Math.round(amount);
        if (scroll_object.prop) {
            if (amount > scroll_object.prop('scrollTop') && amount > 0) {
                scroll_object.prop('scrollTop', 0);
            }
            pos = scroll_object.prop('scrollTop');
            scroll_object.scrollTop(pos + amount);
            return self;
        } else {
            if (amount > scroll_object.attr('scrollTop') && amount > 0) {
                scroll_object.attr('scrollTop', 0);
            }
            pos = scroll_object.attr('scrollTop');
            scroll_object.scrollTop(pos + amount);
            return self;
        }
    },
...
self.mousewheel(function(event, delta) {
    if (delta > 0) {
        self.scroll(-40);
    } else {
        self.scroll(40);
    }
    return false;
}, true);
jcubic
  • 61,973
  • 54
  • 229
  • 402
  • I am already using it. But it doesn't fire on a body with hidden overflow (no scrollbar) – Marco C Aug 09 '13 at 06:00
  • 1
    @MarcoCalì I'm using it here http://terminal.jcubic.pl/multiply-interpreters-demo.html (jquery terminal) and it work. But in Webkit browsers I scroll html element instead of body, but the event is attached to body. – jcubic Aug 09 '13 at 06:07
  • The code I post is a plugin attached to `$('body').plugin` so `this` becomde `$('body')` in my code. In firefox `scroll_object` need to be a body. – jcubic Aug 09 '13 at 06:23