Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

jquery-mousewheel

jquery892.9kMIT3.2.2TypeScript support: definitely-typed

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

jquery, mouse, wheel, event, mousewheel, jquery-plugin, browser

readme

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 deprecated 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 - not recommended!
$( "#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.

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 & running tests

git clone git@github.com:jquery/jquery-mousewheel.git
cd jquery-mousewheel/
npm install
npm test

The unit tests 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.

changelog

Mouse Wheel ChangeLog

3.2.2

  • Include the minified file in the npm package

3.2.1

  • Update README

3.2.0

  • Use .on()/.off() for event binding where available
  • Don't clobber mouse offset properties if we don't adjust them (#165)
  • Remove moot version property from bower.json (#140)
  • Remove the executable bit from the library (#176)
  • Add jtr-based tests in GitHub Actions, migrate to ESLint flat config (#247)

3.1.13

  • Update copyright notice and license to remove years
  • Create the correct compressed version
  • Remove the obsolete jQuery Plugin Registry file

3.1.12

  • Fix possible 0 value for line height when in delta mode 1

3.1.11

  • Fix version number for package managers...

3.1.10

  • Fix issue with calculating line height when using older versions of jQuery
  • Add offsetX/Y normalization with setting to turn it off
  • Cleans up data on teardown

3.1.9

  • Fix bower.json file
  • Updated how the deltas are adjusted for older mousewheel based events that have deltas that are factors of 120.
  • Add $.event.special.mousewheel.settings.adjustOldDeltas (defaults to true) to turn off adjusting of old deltas that are factors of 120. You'd turn this off if you want to be as close to native scrolling as possible.

3.1.8

  • Even better handling of older browsers that use a wheelDelta based on 120
  • And fix version reported by $.event.special.mousewheel

3.1.7

  • Better handle the deltaMode values 1 (lines) and 2 (pages)
  • Attempt to better handle older browsers that use a wheelDelta based on 120

3.1.6

  • Deprecating delta, deltaX, and deltaY event handler arguments
  • Update actual event object with normalized deltaXand deltaY values (event.deltaX, event.deltaY)
  • Add deltaFactor to the event object (event.deltaFactor)
  • Handle > 0 but < 1 deltas better
  • Do not fire the event if deltaX and deltaY are 0
  • Better handle different devices that give different lowestDelta values
  • Add $.event.special.mousewheel.version
  • Some clean up

3.1.5

  • Bad release because I did not update the new $.event.special.mousewheel.version

3.1.4

  • Always set the deltaY
  • Add back in the deltaX and deltaY support for older Firefox versions

3.1.3

  • Include MozMousePixelScroll in the to fix list to avoid inconsistent behavior in older Firefox

3.1.2

  • Include grunt utilities for development purposes (jshint and uglify)
  • Include support for browserify
  • Some basic cleaning up

3.1.1

  • Fix rounding issue with deltas less than zero

3.1.0

  • Fix Firefox 17+ issues by using new wheel event
  • Normalize delta values
  • Adds horizontal support for IE 9+ by using new wheel event
  • Support AMD loaders

3.0.6

  • Fix issue with delta being 0 in Firefox

3.0.5

  • jQuery 1.7 compatibility

3.0.4

  • Fix IE issue

3.0.3

  • Added deltaX and deltaY for horizontal scrolling support (Thanks to Seamus Leahy)

3.0.2

  • Fixed delta being opposite value in latest Opera
  • No longer fix pageX, pageY for older Mozilla browsers
  • Removed browser detection
  • Cleaned up the code

3.0.1

  • Bad release... creating a new release due to plugins.jquery.com issue :(

3.0

  • Uses new special events API in jQuery 1.2.2+
  • You can now treat mousewheel as a normal event and use .bind, .unbind and .trigger
  • Using jQuery.data API for expandos

2.2

  • Fixed pageX, pageY, clientX and clientY event properties for Mozilla based browsers

2.1.1

  • Updated to work with jQuery 1.1.3
  • Used one instead of bind to do unload event for clean up

2.1

  • Fixed an issue with the unload handler

2.0

  • Major reduction in code size and complexity (internals have change a whole lot)

1.0

  • Fixed Opera issue
  • Fixed an issue with children elements that also have a mousewheel handler
  • Added ability to handle multiple handlers