Skip to content

[] #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 32 commits into from
Closed

[] #214

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
61d5cc8
pull in grunt-bump to better deal with all the version references
brandonaaron Sep 6, 2014
c559933
need to have version in one spot in this file to support the new bump…
brandonaaron Sep 6, 2014
cdfbed8
Bump version to 3.2.0-pre and jQuery dependency to 1.7+
brandonaaron Nov 14, 2013
34b44f4
Remove the mousewheel/unmousewheel helper methods in favor of
brandonaaron Nov 14, 2013
0442436
Add the trigger hook to actually have a functioning trigger
brandonaaron Nov 14, 2013
ee9753c
No longer add delta, deltaX, and deltaY to the event handler arguments
brandonaaron Nov 14, 2013
d6f336c
Add examples directory and beginings of the unit tests
brandonaaron Nov 14, 2013
eca265b
add 3.2.0-pre info to the Changelog
brandonaaron Nov 14, 2013
7a678f0
update the classic physical test to work with the latest updates
brandonaaron Nov 14, 2013
b4001b3
Support debounce and throttle behaviors via the data object.
brandonaaron Nov 14, 2013
229a320
Add throttling to #test6 to see the throttle behavior in action
brandonaaron Nov 14, 2013
193b7c2
Update changelog
brandonaaron Nov 14, 2013
e9ad1a8
Move event fixing logic into exposed function at
brandonaaron Nov 14, 2013
92b5f23
remove the throttle usage from physical test for now as it changes th…
brandonaaron Nov 14, 2013
bd85d36
Update deltas to follow the new wheel event convention
brandonaaron Nov 15, 2013
7396b7e
Include updated details regarding deltas in the readme
brandonaaron Nov 15, 2013
015bb5c
Actually lets call it 4.0.0-pre considering the delta sign update
brandonaaron Nov 15, 2013
e86ab9b
Fix directions on the physical test output.
brandonaaron Nov 15, 2013
9f8fcb5
update the unit test with the correct directions
brandonaaron Nov 15, 2013
fbb13f4
fix bad merge
brandonaaron Nov 20, 2013
8163c9c
Add simple intent setting and tweak how throtte/debounce is set.
brandonaaron Nov 20, 2013
f8c8067
Allow preventDefault and stopPropagation to function for events that are
brandonaaron Nov 20, 2013
65476d9
No need to have this check anymore
brandonaaron Nov 20, 2013
767b98e
Update intent feature to monitor mouse movement. Allow intent and
brandonaaron Nov 20, 2013
e73b246
Add maxDelay option for debounce feature.
brandonaaron Nov 20, 2013
7a89afb
Add leading and trailing options to throttle and debounce features
brandonaaron Nov 21, 2013
aebc680
Only preventDefault/stopPropagation for events that are not passed on
brandonaaron Nov 21, 2013
9e27e53
return the value of the handler for the delayed handlers
brandonaaron Nov 21, 2013
f620d0c
Add some comments and reorganize a little
brandonaaron Nov 21, 2013
878959f
update scroll test
brandonaaron Dec 14, 2013
841a342
jshint, i should run it more
brandonaaron Dec 14, 2013
5e0a298
fix bad rebase, whoops.
brandonaaron Sep 6, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Mouse Wheel ChangeLog

## 4.0.0-pre

* BREAKING: Now requires jQuery 1.7+
* BREAKING: Match delta signs (+-) to that of the newer wheel event standard.
* BREAKING: Removed delta, deltaX, and deltaY from the event handler args. Use deltaX and deltaY properties from the event object instead.
* BREAKING: Remove mousewheel/unmousehweel helper functions in preference of just using $().on and $().trigger
* Added support for throttling/debouncing via data argument, example: $(...).on('mousewheel', { mousewheel: { behavior: 'throttle', delay: 100 } }, function(event) {...})
* Added trigger hook so that triggering a mousewheel event works properly, example: $().trigger( $.Event('mousewheel', { deltaX: 0, deltaY: 120 }) );
* Add examples directory
* Add proper unit tests in addition to tried and true physical test

## 3.1.12

* Fix possible 0 value for line height when in delta mode 1
Expand Down
9 changes: 9 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ module.exports = function(grunt) {
}
}
}
},
bump: {
options: {
files: ['package.json', 'mousewheel.jquery.json', 'bower.json', 'jquery.mousewheel.js'],
commit: false,
createTag: false,
push: false
}
}
});

// Load the plugin that provides the 'uglify' task.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-bump');

// Default task(s).
grunt.registerTask('default', ['jshint', 'uglify']);
Expand Down
49 changes: 44 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,39 @@ $('#my_elem').mousewheel(function(event) {
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.
The combination of browsers, operating systems, devices, and user settings 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](http://mousewheeldatacollector.herokuapp.com/).

### Which direction

One way of understanding the direction is to understand which direction the user it trying to move the content.
This happens to also align with the natural scroll setting in the latest version of OS X.
A positive `deltaX` or `deltaY` means the user wants to move the content to west (to the left) or north (upwards) respectively.
A negative `deltaX` or `deltaY` means the user wants to move the content to east (to the right) or south (downwards) respectively.

```js
var directions = {
isNorth: function(deltaY) { return deltaY > 0; },
isEast: function(deltaX) { return deltaX < 0; },
isSouth: function(deltaY) { return deltaY < 0; },
isWest: function(deltaX) { return deltaX > 0; },
isNorthEast: function(deltaX, deltaY) { return deltaX < 0 && deltaY > 0; },
isNorthWest: function(deltaX, deltaY) { return deltaX > 0 && deltaY > 0; },
isSouthEast: function(deltaX, deltaY) { return deltaX < 0 && deltaY < 0; },
isSouthWest: function(deltaX, deltaY) { return deltaX > 0 && deltaY < 0; }
};
```

#### Older Versions

In older versions of this plugin the delta value signs are the opposite. The deltaY value in this version align with
the newer wheel event standard which flipped the delta signs from the old wheelDelta properties.

### 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
Expand All @@ -47,6 +71,21 @@ 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.

Here is an example of updating the scroll amount of an element based on the mouse wheel event.

```js
var $elem = $('#my_elem');
$elem.on('mousewheel', function(event) {
event.preventDefault();

var top = $elem.scrollTop(),
left = $elem.scrollLeft(),

$elem
.scrollTop( event.deltaY * event.deltaFactor )
.scrollLeft( event.deltaX * event.deltaFactor );
});
```

## See it in action
[See the tests on Github](http://brandonaaron.github.io/jquery-mousewheel/test).
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-mousewheel",
"version": "3.1.12",
"version": "4.0.0-pre",
"main": "./jquery.mousewheel.js",
"ignore": [
"*.json",
Expand All @@ -12,6 +12,6 @@
"test"
],
"dependencies": {
"jquery": ">=1.2.2"
"jquery": ">=1.7"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading