A jQuery plugin that adds cross-browser mouse wheel support.

Overview

jQuery Mouse Wheel Plugin

A jQuery plugin that adds cross-browser mouse wheel support with delta normalization.

In order to use the plugin, simply bind the mousewheel event to an element.

It also provides two helper methods called mousewheel and unmousewheel that act just like other event helper methods in jQuery.

The event object is updated with the normalized deltaX and deltaY properties. In addition there is a new property on the event object called deltaFactor. Multiply the deltaFactor by deltaX or deltaY to get the scroll distance that the browser has reported.

Here is an example of using both the bind and helper method syntax:

// using on
$('#my_elem').on('mousewheel', function(event) {
    console.log(event.deltaX, event.deltaY, event.deltaFactor);
});

// using the event helper
$('#my_elem').mousewheel(function(event) {
    console.log(event.deltaX, event.deltaY, event.deltaFactor);
});

The old behavior of adding three arguments (delta, deltaX, and deltaY) to the event handler is now deprecated and will be removed in later releases.

The Deltas...

The combination of browsers, operating systems, and devices offer a huge range of possible delta values. In fact if the user uses a trackpad and then a physical mouse wheel the delta values can differ wildly. This plugin normalizes those values so you get a whole number starting at +-1 and going up in increments of +-1 according to the force or acceleration that is used. This number has the potential to be in the thousands depending on the device. Check out some of the data collected from users here.

Getting the scroll distance

In some use-cases we prefer to have the normalized delta but in others we want to know how far the browser should scroll based on the users input. This can be done by multiplying the deltaFactor by the deltaX or deltaY event property to find the scroll distance the browser reported.

The deltaFactor property was added to the event object in 3.1.5 so that the actual reported delta value can be extracted. This is a non-standard property.

Building the code in the repo

$ git clone [email protected]:jquery/jquery-mousewheel.git
$ cd jquery-mousewheel/
$ npm install
$ npm run build
$ npm run karma

The unit tests run by karma are very basic sanity checks; improvements welcome. To fully test the plugin, load test/index.html in each supported browser and follow the instructions at the top of the file after the unit tests finish.

Comments
  • osx inertia

    osx inertia

    hi!

    when using a trackpad or a magic mouse multiple events are triggered for every touch-scroll, sometimes taking as long as 1-2 seconds to stop, depending the scrolling "speed" and due to the inertia setting on mac osx.

    I'm using mousewheel in a scenario where I move through news items on mousewheel and ideally I only want to move by on one each mousewheel action on windows, one each touch-scroll gesture on a mac trackpad.

    The multiple events triggered make this impossible to do. I've tried unbinding and rebinding but as soon as I rebind the events triggered by the touch action before the unbind keep getting detected. I've tried filtering the delta to only scroll if it's between 2 values but its making the scroll very unreliable. Rebinding mousewheel only after the inertia events stop is also an impossibility because it would mean only allowing one scroll every two seconds.

    do you have any ideas on how to overcome this?

    Feature 
    opened by annam 69
  • mousewheel event doesn't work on Safari (tested on 5.1.7) for windows.

    mousewheel event doesn't work on Safari (tested on 5.1.7) for windows.

    Hi, Thanks for this excelent plugin (very usefull). It seems that mousewheel event doesn't work on Safari (tested on 5.1.7) for windows. is there a way to fix it properly ? Thanks.

    opened by gui-yem 15
  • Support for passive event handlers

    Support for passive event handlers

    Chrome 51 introduced passive event handlers. Maybe the performance of jquery-mousewheel can be improved with this:

    • https://developers.google.com/web/updates/2016/06/passive-event-listeners

    Read more:

    • https://medium.com/@devlucky/about-passive-event-listeners-224ff620e68c#.fd3mjfvp4

    Because I sometimes get this when using jquery.mousewheel.js:

    Handling of 'wheel' input event was delayed for 730 ms due to main thread being busy. Consider marking event handler as 'passive' to make the page more responive.

    opened by bennycode 14
  • deltaFactor for Yandex is too big

    deltaFactor for Yandex is too big

    In webkit when scrolling with mouse wheel we get a huge deltaFactor.

    I use webkit based browser and I open a simple text page. I use mouse wheel to scroll. So I do only one scroll step and I get this numbers:

    evt.deltaY: -1
    evt.deltaMode: 0
    evt.deltaFactor: 120
    evt.originalEvent.deltaMode: 0
    evt.originalEvent.detail: 0
    evt.originalEvent.wheelDelta: -120
    evt.originalEvent.wheelDeltaY: -120
    

    If I check the difference in document.body.scrollTop it is only 4px. So, it looks like deltaFactor must be 4 in this case.

    Here is a little screencast: https://www.monosnap.com/file/oatLFlX9U41gFeUDPRZsbF5zngjPQ3

    And here is how mootools deal with delta (strange one but they also handle 120 as a constant for something):

    (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3
    

    source https://github.com/mootools/mootools-core/blob/master/Source/Types/DOMEvent.js#L55-L56

    opened by chestozo 14
  • middle click

    middle click

    with modern mice middle click is performed through the central wheel.

    However, apparently the plugin converts all wheel events to a delta, i.e. a wheel turn.

    How do I detect a simple click?

    opened by paolobenve 11
  • Delta properties are not being copied to jq event object

    Delta properties are not being copied to jq event object

    function (event) { console.log(event) }

    altKey: false
    bubbles: true
    button: 0
    buttons: undefined
    cancelable: true
    clientX: 716
    clientY: 414
    ctrlKey: false
    currentTarget: div#va-accordion.va-container.no-margin
    data: null
    delegateTarget: div#va-accordion.va-container.no-margin
    eventPhase: 3
    handleObj: Object
    isDefaultPrevented: function k(){return!0}
    isPropagationStopped: function k(){return!0}
    jQuery211019673938816413283: true
    metaKey: false
    offsetX: 549
    offsetY: 159
    originalEvent: WheelEvent
    pageX: 716
    pageY: 4371
    relatedTarget: null
    result: false
    screenX: 716
    screenY: 509
    shiftKey: false
    target: div.va-slice.va-slice-1.expanded
    timeStamp: 1413607436027
    toElement: div.va-slice.va-slice-1.expanded
    type: "mousewheel"
    view: Window
    which: 1
    

    function (event) { console.log(event.originalEvent) }

    altKey: false
    bubbles: true
    button: 0
    cancelBubble: false
    cancelable: true
    charCode: 0
    clientX: 716
    clientY: 414
    clipboardData: undefined
    ctrlKey: false
    currentTarget: null
    dataTransfer: null
    defaultPrevented: true
    deltaMode: 0
    deltaX: -0
    deltaY: 2
    deltaZ: 0
    detail: 0
    eventPhase: 0
    fromElement: null
    keyCode: 0
    layerX: 549
    layerY: 159
    metaKey: false
    offsetX: 549
    offsetY: 159
    pageX: 716
    pageY: 4371
    path: NodeList[0]
    relatedTarget: null
    returnValue: false
    screenX: 716
    screenY: 509
    shiftKey: false
    srcElement: div.va-slice.va-slice-1.expanded
    target: div.va-slice.va-slice-1.expanded
    timeStamp: 1413607436027
    toElement: div.va-slice.va-slice-1.expanded
    type: "wheel"
    view: Window
    webkitDirectionInvertedFromDevice: false
    webkitMovementX: 0
    webkitMovementY: 0
    wheelDelta: -6
    wheelDeltaX: 0
    wheelDeltaY: -6
    which: 1
    x: 716
    y: 414
    
    $.fn.jquery
    2.1.1
    
    opened by htchaan 11
  • Not working with dell xps 9343 in IE & Edge

    Not working with dell xps 9343 in IE & Edge

    This is not working with the trackpad of my dell xps 13 9343.

    It works in chrome and mozilla & opera, but not in internet explorer & edge (Edge/14.14393) & safari

    opened by Marthaarman 10
  • mousewheel event doesn't work in Firefox 27 on MAC

    mousewheel event doesn't work in Firefox 27 on MAC

    Doesn't seem to be working as it's suppose to here. Version 26 no problem, yet while updating to 27 something changed, in the test case everything seems to be normal, so very hard to tell what's going on. Any ideas? :)

    opened by jonaslund 10
  • Horizontal scrolling issue

    Horizontal scrolling issue

    Hey If the mouse is near the bottom scrollbar, but obviously inside the page, scrolling does not happen, strangely. Only if the mouse is moved towards the content does the scrolling re-initiates.

    Strange behavior in any case!

    Thanks.

    opened by arjunmenon 9
  • How to

    How to

    I'm not sure how to use this on the $('body) ..

    I tried this for testing and the scroll doesn't work..

    $('body').on('mousewheel', function (event) {
         console.log(event.deltaX, event.deltaY, event.deltaFactor);
    });
    
    opened by polikin 8
  • Move delta args inside event object

    Move delta args inside event object

    The reasoning is simple. Imagine having a scrollable element and a separate element, emulating a scrollbar. Mousewheel events on the scrollbar should trigger target element's mousewheel event, but a simple call to trigger is impossible due to the fact that delta parameters cannot be passed on.

    Now if delta params are inside the event object, then proxying the event is as simple as

    $('#scrollbar').on('mousewheel', function (event) {
        $('#scrollable-element').trigger($.extend($.Event('mousewheel'), {
            delta: event.delta,
            deltaX: event.deltaX,
            deltaY: event.deltaY
        }));
    });
    
    opened by kpobococ 8
  • Code does not allow for the ability to scroll horizontally (when clicking Shift + Mouse Wheel)

    Code does not allow for the ability to scroll horizontally (when clicking Shift + Mouse Wheel)

    When I apply this code to my Slickgrid, I can no longer scroll horizontally when I Press Shift + Mouse Scroll. Horizontal scrolling was working previously.

    opened by ibrahimGit123 0
  • Option to change the mouse wheel direction

    Option to change the mouse wheel direction

    Right now, it seems to move opposite to the browser scrolling. If you move wheel up, then the slider moves forward which is opposite of how browser works. Is there an option to reverse it?

    opened by rahulbroy 0
  • Please make non-passive event listeners

    Please make non-passive event listeners

    I believe I'm seeing a warning error in Google Chrome saying:

    [Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952

    This is pointing to the following code line: https://github.com/jquery/jquery-mousewheel/blob/fcb425e872c5b1eb45cbc4c8a5dcf4865b991bab/jquery.mousewheel.js#L40

    opened by ghost 13
  • For some reason the minified file missing in npm

    For some reason the minified file missing in npm

    How to reproduce:

    /tmp/123$ npm install jquery-mousewheel  
    /tmp/123  
    └── [email protected]  
      
    /tmp/123$ ls -aR  
    .            ..           node_modules  
      
    ./node_modules:  
    .                 ..                jquery-mousewheel  
      
    ./node_modules/jquery-mousewheel:  
    .                    ChangeLog.md         README.md            package.json  
    ..                   LICENSE.txt          jquery.mousewheel.js
    
    opened by artyil 1
  • Safari 9 scroll is either 1 or -1

    Safari 9 scroll is either 1 or -1

    On Safari 9.0 (the latest), event.deltaY is either 1, or -1. It never goes any higher than that. So it's not consistent across browsers. On Chrome it works fine.

    screen shot 2015-10-22 at 11 30 56 am

    screen shot 2015-10-22 at 11 31 05 am

    opened by drewbaker 30
Owner
jQuery
jQuery
Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed.

scrooth Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed. Why? I needed that, and I was unable to find p

Rafał Spiżewski 20 Aug 29, 2022
We are creating a Library that would ensure developers do not reinvent the wheel anymore as far as Authentication is concerned. Developers can easily register and download authentication codes that suits their need at any point.

#AuthWiki Resource Product Documentation Figma Database Schema First Presentation Live Link API Documentation Individual Contributions User Activity U

Zuri Training 17 Dec 2, 2022
A vanilla-js module for adding zoom-on-wheel and pan-on-drag behavior to inline SVG elements.

svg-pan-zoom-container A vanilla-js module for adding zoom-on-wheel and pan-on-drag behavior to inline SVG elements. No need to write scripts. Just ma

31 Dec 10, 2022
jquery plugin to convert number inputs into knobs that can be adjusted by dragging with mouse or fingers

jquery-knobby is a jquery plugin to convert number input elements into turnable knobs that can be adjusted by cyclic dragging with mouse or fingers -

null 4 Oct 2, 2020
Freewall is a cross-browser and responsive jQuery plugin to help you create grid, image and masonry layouts for desktop, mobile, and tablet...

Freewall Freewall is a cross-browser and responsive jQuery plugin to help you create many types of grid layouts: flexible layouts, images layouts, nes

Minh Nguyen 1.9k Dec 27, 2022
A super-lightweight, highly configurable, cross-browser date / time picker jQuery plugin

Zebra Datepicker A super-lightweight, highly configurable, cross-browser date/time picker jQuery plugin Zebra_Datepicker is a small yet and highly con

Stefan Gabos 391 Dec 29, 2022
This is a Homebridge plugin that adds HomeKit support to Tidbyt devices.

Tidbyt Platform Plugin This is a Homebridge plugin that adds HomeKit support to Tidbyt devices. Built with node-tidbyt. This project is not endorsed o

Nicholas Penree 18 Nov 20, 2022
A mojo.js plugin that adds support for ejs templates.

A mojo.js plugin that adds support for ejs templates. The code of this plugin is a good example for learning to build new plugins, you're welcome to fork it.

Mojolicious 4 Jun 9, 2022
A small plugin for Frappe that adds the support of customizations to the attach control.

Frappe Better Attach Control A small plugin for Frappe that adds the support of customizations to the attach control. Table of Contents Requirements S

Ameen Ahmed 17 Dec 25, 2022
adds the *scrollin* and *scrollout* events to jquery, which will fire when any given element becomes (respectively) visible and invisible in the browser viewpori

jQuery.scrolling This plugin adds the scrollin and scrollout events to jquery: these events will fire when any given element becomes visible/invisible

Dark 5 Apr 7, 2021
Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Stephanie Eckles 65 Nov 2, 2022
🖼 A jQuery plugin to view images just like in Windows. Browser support IE7+!

⚠️ Attention! This repository will be maintained just in small iteration. The plugin is easy to use, but its customization can be troublesome. To impr

Zongbin 191 Dec 30, 2022
Adds promise support (rejects(), doesNotReject()) to tape by decorating it using tape-promise.

Tape With Promises Adds promise support (rejects(), doesNotReject()) to tape by decorating it using tape-promise. Install npm install --save-dev @smal

Small Technology Foundation 3 Mar 21, 2022
Adds support for Blade templates to Prettier. (work in progress)

Laravel Blade support for Prettier ⚠️ This plugin is still a work-in-progress. If you're trying it out, please keep this in mind. This package include

Ryan Chandler 139 Sep 20, 2022
Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all with IndexedDB. Perfectly suitable for your next (PWA) app.

BrowstorJS ?? ?? ?? Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all

Nullix 8 Aug 5, 2022
A JavaScript animation plugin for menus. It creates a div that moves when you mouse over an element, giving it an elastic animation.

Lava-Lamp Description: A JavaScript animation plugin for menus. It creates a div that moves when you mouse over an element, giving it an elastic anima

Richard Hung 38 Jun 4, 2022
Cross-browser plugin to remove addictive features on YouTube like thumbnails, comments, previews and more...

ZenTube Installation Features Remove some (more) elements from Youtube to make it less addictive. Mix and match between the following options: Hide or

inversepolarity 57 Dec 17, 2022
Hacker Tools cross-platform desktop App, support windows/MacOS/LInux ....

Hacker Tools cross-platform desktop App, support windows/MacOS/LInux ....

51pwn 29 Jan 8, 2023
Simple patch that adds a 'progress' callback to jquery Ajax calls

Jquery Ajax Progresss A simple patch to jQuery that will call a 'progress' callback, using the XHR.onProgress event Usage Simply include the script on

Chad Engler 118 Sep 8, 2022