1
Fork 0

Add jquery-mousewheel v3.1.11.

master
vonavi 2014-07-08 16:43:18 +03:00
parent 8219c0d03a
commit c6593632cd
17 changed files with 10395 additions and 0 deletions

View File

@ -0,0 +1,4 @@
.DS_Store
/npm-debug.log
/node_modules
/test/browserify/node_modules

View File

@ -0,0 +1,19 @@
{
"bitwise": true,
"browser": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"indent": 4,
"jquery" : true,
"latedef": true,
"noarg": true,
"node": true,
"noempty": true,
"plusplus": false,
"quotmark": "single",
"strict": false,
"trailing": true,
"unused": true,
"globals": { "define": true, "require": true }
}

View File

@ -0,0 +1,137 @@
# Mouse Wheel ChangeLog
## 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 `deltaX `and `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

View File

@ -0,0 +1,47 @@
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: ['jquery.mousewheel.js']
},
uglify: {
options: {
compress: true,
mangle: true,
preserveComments: 'some',
report: 'gzip'
},
build: {
src: 'jquery.mousewheel.js',
dest: 'jquery.mousewheel.min.js'
}
},
connect: {
server: {
options: {
hostname: '*',
keepalive: true,
middleware: function(connect, options) {
return [
connect.static(options.base),
connect.directory(options.base)
];
}
}
}
}
});
// Load the plugin that provides the 'uglify' task.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-connect');
// Default task(s).
grunt.registerTask('default', ['jshint', 'uglify']);
};

View File

@ -0,0 +1,20 @@
Copyright (c) 2013, Brandon Aaron (http://brandon.aaron.sh)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,85 @@
# jQuery Mouse Wheel Plugin
A [jQuery](http://jquery.com/) 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:
```js
// 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](http://mousewheeldatacollector.herokuapp.com/).
### 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.
## See it in action
[See the tests on Github](http://brandonaaron.github.io/jquery-mousewheel/test).
## Using with [Browserify](http://browserify.org)
Support for browserify is baked in.
```bash
npm install jquery-mousewheel
npm install jquery-browserify
```
In your server-side node.js code:
```js
var express = require('express');
var app = express.createServer();
app.use(require('browserify')({
require : [ 'jquery-browserify', 'jquery-mousewheel' ]
}));
```
In your browser-side javascript:
```js
var $ = require('jquery-browserify');
require('jquery-mousewheel')($);
```
## License
This plugin is licensed under the [MIT License](LICENSE.txt).
Copyright (c) 2013 [Brandon Aaron](http://brandon.aaron.sh)

View File

@ -0,0 +1,16 @@
{
"name": "jquery-mousewheel",
"version": "3.1.11",
"main": "./jquery.mousewheel.js",
"ignore": [
"*.json",
"*.markdown",
"*.txt",
".*",
"Gruntfile.js",
"test"
],
"dependencies": {
"jquery": ">=1.2.2"
}
}

View File

@ -0,0 +1,220 @@
/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 3.1.11
*
* Requires: jQuery 1.2.2+
*/
(function (factory) {
if ( typeof define === 'function' && define.amd ) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS style for Browserify
module.exports = factory;
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
slice = Array.prototype.slice,
nullLowestDeltaTimeout, lowestDelta;
if ( $.event.fixHooks ) {
for ( var i = toFix.length; i; ) {
$.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
}
}
var special = $.event.special.mousewheel = {
version: '3.1.11',
setup: function() {
if ( this.addEventListener ) {
for ( var i = toBind.length; i; ) {
this.addEventListener( toBind[--i], handler, false );
}
} else {
this.onmousewheel = handler;
}
// Store the line height and page height for this particular element
$.data(this, 'mousewheel-line-height', special.getLineHeight(this));
$.data(this, 'mousewheel-page-height', special.getPageHeight(this));
},
teardown: function() {
if ( this.removeEventListener ) {
for ( var i = toBind.length; i; ) {
this.removeEventListener( toBind[--i], handler, false );
}
} else {
this.onmousewheel = null;
}
// Clean up the data we added to the element
$.removeData(this, 'mousewheel-line-height');
$.removeData(this, 'mousewheel-page-height');
},
getLineHeight: function(elem) {
var $parent = $(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']();
if (!$parent.length) {
$parent = $('body');
}
return parseInt($parent.css('fontSize'), 10);
},
getPageHeight: function(elem) {
return $(elem).height();
},
settings: {
adjustOldDeltas: true, // see shouldAdjustOldDeltas() below
normalizeOffset: true // calls getBoundingClientRect for each event
}
};
$.fn.extend({
mousewheel: function(fn) {
return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
},
unmousewheel: function(fn) {
return this.unbind('mousewheel', fn);
}
});
function handler(event) {
var orgEvent = event || window.event,
args = slice.call(arguments, 1),
delta = 0,
deltaX = 0,
deltaY = 0,
absDelta = 0,
offsetX = 0,
offsetY = 0;
event = $.event.fix(orgEvent);
event.type = 'mousewheel';
// Old school scrollwheel delta
if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
// Firefox < 17 horizontal scrolling related to DOMMouseScroll event
if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
deltaX = deltaY * -1;
deltaY = 0;
}
// Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
delta = deltaY === 0 ? deltaX : deltaY;
// New school wheel delta (wheel event)
if ( 'deltaY' in orgEvent ) {
deltaY = orgEvent.deltaY * -1;
delta = deltaY;
}
if ( 'deltaX' in orgEvent ) {
deltaX = orgEvent.deltaX;
if ( deltaY === 0 ) { delta = deltaX * -1; }
}
// No change actually happened, no reason to go any further
if ( deltaY === 0 && deltaX === 0 ) { return; }
// Need to convert lines and pages to pixels if we aren't already in pixels
// There are three delta modes:
// * deltaMode 0 is by pixels, nothing to do
// * deltaMode 1 is by lines
// * deltaMode 2 is by pages
if ( orgEvent.deltaMode === 1 ) {
var lineHeight = $.data(this, 'mousewheel-line-height');
delta *= lineHeight;
deltaY *= lineHeight;
deltaX *= lineHeight;
} else if ( orgEvent.deltaMode === 2 ) {
var pageHeight = $.data(this, 'mousewheel-page-height');
delta *= pageHeight;
deltaY *= pageHeight;
deltaX *= pageHeight;
}
// Store lowest absolute delta to normalize the delta values
absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
if ( !lowestDelta || absDelta < lowestDelta ) {
lowestDelta = absDelta;
// Adjust older deltas if necessary
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
lowestDelta /= 40;
}
}
// Adjust older deltas if necessary
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
// Divide all the things by 40!
delta /= 40;
deltaX /= 40;
deltaY /= 40;
}
// Get a whole, normalized value for the deltas
delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
// Normalise offsetX and offsetY properties
if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
var boundingRect = this.getBoundingClientRect();
offsetX = event.clientX - boundingRect.left;
offsetY = event.clientY - boundingRect.top;
}
// Add information to the event object
event.deltaX = deltaX;
event.deltaY = deltaY;
event.deltaFactor = lowestDelta;
event.offsetX = offsetX;
event.offsetY = offsetY;
// Go ahead and set deltaMode to 0 since we converted to pixels
// Although this is a little odd since we overwrite the deltaX/Y
// properties with normalized deltas.
event.deltaMode = 0;
// Add event and delta to the front of the arguments
args.unshift(event, delta, deltaX, deltaY);
// Clearout lowestDelta after sometime to better
// handle multiple device types that give different
// a different lowestDelta
// Ex: trackpad = 3 and mouse wheel = 120
if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
return ($.event.dispatch || $.event.handle).apply(this, args);
}
function nullLowestDelta() {
lowestDelta = null;
}
function shouldAdjustOldDeltas(orgEvent, absDelta) {
// If this is an older event and the delta is divisable by 120,
// then we are assuming that the browser is treating this as an
// older mouse wheel event and that we should divide the deltas
// by 40 to try and get a more usable deltaFactor.
// Side note, this actually impacts the reported scroll distance
// in older browsers and can cause scrolling to be slower than native.
// Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
}
}));

View File

@ -0,0 +1,8 @@
/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 3.1.11
*
* Requires: jQuery 1.2.2+
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a:a(jQuery)}(function(a){function b(b){var g=b||window.event,h=i.call(arguments,1),j=0,l=0,m=0,n=0,o=0,p=0;if(b=a.event.fix(g),b.type="mousewheel","detail"in g&&(m=-1*g.detail),"wheelDelta"in g&&(m=g.wheelDelta),"wheelDeltaY"in g&&(m=g.wheelDeltaY),"wheelDeltaX"in g&&(l=-1*g.wheelDeltaX),"axis"in g&&g.axis===g.HORIZONTAL_AXIS&&(l=-1*m,m=0),j=0===m?l:m,"deltaY"in g&&(m=-1*g.deltaY,j=m),"deltaX"in g&&(l=g.deltaX,0===m&&(j=-1*l)),0!==m||0!==l){if(1===g.deltaMode){var q=a.data(this,"mousewheel-line-height");j*=q,m*=q,l*=q}else if(2===g.deltaMode){var r=a.data(this,"mousewheel-page-height");j*=r,m*=r,l*=r}if(n=Math.max(Math.abs(m),Math.abs(l)),(!f||f>n)&&(f=n,d(g,n)&&(f/=40)),d(g,n)&&(j/=40,l/=40,m/=40),j=Math[j>=1?"floor":"ceil"](j/f),l=Math[l>=1?"floor":"ceil"](l/f),m=Math[m>=1?"floor":"ceil"](m/f),k.settings.normalizeOffset&&this.getBoundingClientRect){var s=this.getBoundingClientRect();o=b.clientX-s.left,p=b.clientY-s.top}return b.deltaX=l,b.deltaY=m,b.deltaFactor=f,b.offsetX=o,b.offsetY=p,b.deltaMode=0,h.unshift(b,j,l,m),e&&clearTimeout(e),e=setTimeout(c,200),(a.event.dispatch||a.event.handle).apply(this,h)}}function c(){f=null}function d(a,b){return k.settings.adjustOldDeltas&&"mousewheel"===a.type&&b%120===0}var e,f,g=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],h="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],i=Array.prototype.slice;if(a.event.fixHooks)for(var j=g.length;j;)a.event.fixHooks[g[--j]]=a.event.mouseHooks;var k=a.event.special.mousewheel={version:"3.1.11",setup:function(){if(this.addEventListener)for(var c=h.length;c;)this.addEventListener(h[--c],b,!1);else this.onmousewheel=b;a.data(this,"mousewheel-line-height",k.getLineHeight(this)),a.data(this,"mousewheel-page-height",k.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var c=h.length;c;)this.removeEventListener(h[--c],b,!1);else this.onmousewheel=null;a.removeData(this,"mousewheel-line-height"),a.removeData(this,"mousewheel-page-height")},getLineHeight:function(b){var c=a(b)["offsetParent"in a.fn?"offsetParent":"parent"]();return c.length||(c=a("body")),parseInt(c.css("fontSize"),10)},getPageHeight:function(b){return a(b).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})});

View File

@ -0,0 +1,27 @@
{
"name": "mousewheel",
"title": "jQuery Mousewheel",
"description": "A jQuery plugin that adds cross-browser mouse wheel support.",
"keywords": [
"mousewheel",
"mouse",
"event"
],
"version": "3.1.11",
"author": {
"name": "Brandon Aaron",
"url": "http://brandon.aaron.sh"
},
"licenses": [
{
"type": "MIT",
"url": "https://raw.github.com/brandonaaron/jquery-mousewheel/master/LICENSE.txt"
}
],
"bugs": "https://github.com/brandonaaron/jquery-mousewheel/issues",
"homepage": "https://github.com/brandonaaron/jquery-mousewheel",
"download": "https://github.com/brandonaaron/jquery-mousewheel/tags",
"dependencies": {
"jquery": ">=1.2.2"
}
}

View File

@ -0,0 +1,44 @@
{
"name": "jquery-mousewheel",
"version": "3.1.11",
"author": "Brandon Aaron (http://brandon.aaron.sh)",
"description": "A jQuery plugin that adds cross-browser mouse wheel support.",
"license": "MIT",
"homepage": "https://github.com/brandonaaron/jquery-mousewheel",
"main": "./jquery.mousewheel.js",
"repository": {
"type": "git",
"url": "https://github.com/brandonaaron/jquery-mousewheel.git"
},
"bugs": {
"url": "https://github.com/brandonaaron/jquery-mousewheel/issues"
},
"keywords": [
"jquery",
"mouse",
"wheel",
"event",
"mousewheel",
"plugin",
"browser"
],
"files": [
"ChangeLog.md",
"jquery.mousewheel.js",
"README.md"
],
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-jshint": "~0.7.1",
"grunt-contrib-uglify": "~0.2.7"
},
"directories": {
"test": "test"
},
"jam": {
"dependencies": {
"jquery": ">=1.2.2"
}
}
}

View File

@ -0,0 +1,15 @@
# browserify test
First run
```js
npm install jquery-browserify
```
Then run
```js
browserify main.js > bundle.js
```
Then open index.html and console and scroll with the mousewheel. Should see the events being logged.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
<script src="bundle.js"></script>
<script>
$(document).bind('mousewheel', function(e) { console.log(e); });
</script>

View File

@ -0,0 +1,2 @@
var $ = require('jquery-browserify');
require('../../jquery.mousewheel.js')($);

View File

@ -0,0 +1,239 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="iso-8859-1">
<title>Testing mousewheel plugin</title>
<style>
html {
font: 13px Arial, sans-serif;
}
#stage {
color: #fff;
position: relative;
zoom: 1;
}
#test1, #test2, #test3, #test4, #test5, #test6, #test7 {
float: left;
}
#test1 {
background-color: #000;
width: 120px;
height: 100px;
}
#test2 {
background-color: #333;
width: 120px;
height: 100px;
}
#test3 {
background-color: #666;
width: 120px;
height: 100px;
}
#test4 {
background-color: #000;
width: 120px;
height: 100px;
}
#test5 {
background-color: #333;
padding: 5px;
width: 400px;
height: 400px;
}
#test6 {
background-color: #666;
padding: 5px;
width: 250px;
height: 250px;
}
#test7 {
background-color: #000;
padding: 5px;
width: 100px;
height: 100px;
}
#forceScroll {
clear: both;
height: 1000px;
}
#logger {
position: absolute;
top: 100px;
left: 0;
width: 480px;
height: 310px;
overflow: auto;
z-index: 100;
}
#logger p {
color: #000;
padding: 2px;
border-bottom: 1px solid #ccc;
margin: 0;
}
#logger p:nth-child(even) {
background-color: #ffffe8;
}
#logger p:nth-child(10n) {
border-bottom-color: #000;
}
</style>
<script>
(function() {
var verMatch = /v=([\w\.]+)/.exec(location.search),
version = verMatch && verMatch[1],
src;
if (version)
src = 'code.jquery.com/jquery-' + version;
else
src = 'code.jquery.com/jquery-git';
document.write('<script src="http://' + src + '.js"><\/script>');
})();
</script>
<script>
$(function() {
$('#userAgent').html(navigator.userAgent);
$('#jqueryVersion').html($.fn.jquery);
var loghandle = function(event, delta) {
var o = '', id = event.currentTarget.id || event.currentTarget.nodeName;
o = '#' + id + ':';
if (delta > 0)
o += ' up (' + delta + ')';
else if (delta < 0)
o += ' down (' + delta + ')';
if (event.deltaY > 0)
o += ' north (' + event.deltaY + ')';
else if (event.deltaY < 0)
o += ' south (' + event.deltaY + ')';
if (event.deltaX > 0)
o += ' east (' + event.deltaX + ')';
else if (event.deltaX < 0)
o += ' west (' + event.deltaX + ')';
o += ' deltaFactor (' + event.deltaFactor + ')';
log( o );
};
$(document)
.mousewheel(function(event, delta) {
loghandle(event, delta);
});
$('#test1')
.mousewheel(function(event, delta) {
loghandle(event, delta);
log('pageX: ' + event.pageX + ' pageY: ' + event.pageY );
});
$('#test2')
.mousewheel(function(event, delta) {
loghandle(event, delta);
return false; // prevent default
});
$('#test3')
.hover(function() { log('#test3: mouseover'); }, function() { log('#test3: mouseout'); })
.mousewheel(function() {
log('#test3: I should not have been logged');
})
.unmousewheel();
var testRemoval = function() {
log('#test4: I should not have been logged');
};
$('#test4')
.mousewheel(function(event, delta) {
loghandle(event, delta);
return false;
})
.mousewheel(testRemoval)
.mousewheel(function(event, delta) {
loghandle(event, delta);
return false;
})
.unmousewheel(testRemoval);
$('#test5')
.mousewheel(function(event, delta) {
loghandle(event, delta);
event.stopPropagation();
event.preventDefault();
});
$('#test6')
.mousewheel(function(event, delta) {
loghandle(event, delta);
event.stopPropagation();
event.preventDefault();
});
$('#test7')
.mousewheel(function(event, delta) {
loghandle(event, delta);
event.preventDefault();
});
function log(msg) {
$('#logger').append('<p>' + msg + '<\/p>')[0].scrollTop = 999999;
}
});
</script>
<script src="../jquery.mousewheel.js"></script>
</head>
<body>
<h1 id="banner">jQuery mousewheel.js Test with jQuery <span id="jqueryVersion"></span></h1>
<h2 id="userAgent"></h2>
<ul>
<li><strong>Test1</strong> is just using the plain on <code>mousewheel()</code> with a function passed in and does not prevent default. (Also logs the value of <code>pageX</code> and <code>pageY</code> event properties.)</li>
<li><strong>Test2</strong> should prevent the default action.</li>
<li><strong>Test3</strong> should only log a <code>mouseover</code> and <code>mouseout</code> event. Testing <code>unmousewheel()</code>.</li>
<li><strong>Test4</strong> has two handlers.</li>
<li><strong>Test5</strong> is like Test2 but has children. The children should not scroll until mousing over them.</li>
<li><strong>Test6</strong> is like Test5 but should not scroll children or parents.</li>
<li><strong>Test7</strong> is like Test6 but has no children. It will propagate the event and scroll test 6 as well.</li>
</ul>
<div id="stage">
<div id="test1"><p>Test1</p></div>
<div id="test2"><p>Test2</p></div>
<div id="test3"><p>Test3</p></div>
<div id="test4"><p>Test4</p></div>
<div id="test5">
<p>Test5</p>
<div id="test6">
<p>Test6</p>
<div id="test7"><p>Test7</p></div>
</div>
</div>
<div id="logger"></div>
</div>
<div id="forceScroll"></div>
</body>
</html>

View File

@ -0,0 +1,48 @@
<!doctype html>
<html>
<head>
<title>Scroll Test</title>
<style>
html, body { margin: 0; padding: 0; width: 100%; height: 100%; }
#emulated, #native {
width: 40%;
height: 100%;
}
#emulated { float: left; overflow: hidden; }
#native { float: right; overflow: auto; }
</style>
<script>
(function() {
var verMatch = /v=([\w\.]+)/.exec(location.search),
version = verMatch && verMatch[1],
src;
if (version)
src = 'code.jquery.com/jquery-' + version;
else
src = 'code.jquery.com/jquery-git';
document.write('<script src="http://' + src + '.js"><\/script>');
})();
</script>
<script src="../jquery.mousewheel.js"></script>
<script>
var lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus rhoncus nibh ac ultricies blandit. Nunc blandit blandit lobortis. Maecenas id dolor scelerisque, facilisis dolor eu, interdum urna. Nullam consectetur lectus quis mi interdum accumsan. Nulla malesuada est nec neque suscipit pulvinar. Vivamus sagittis, nunc a porttitor tempus, mi neque eleifend diam, nec porttitor metus dui a orci. Cras tempus lobortis nisl ut sagittis. Maecenas semper in magna mollis venenatis. Vestibulum fermentum tincidunt fringilla.';
$(function() {
for (var i=0; i<30; i++) {
var html = '<p>' + i + ' ' + lorem + '</p>';
$('#emulated').append(html);
$('#native').append(html);
}
$('#emulated').bind('mousewheel', function(event) {
event.preventDefault();
var scrollTop = this.scrollTop;
this.scrollTop = (scrollTop + ((event.deltaY * event.deltaFactor) * -1));
//console.log(event.deltaY, event.deltaFactor, event.originalEvent.deltaMode, event.originalEvent.wheelDelta);
});
});
</script>
</head>
<body>
<div id="emulated"></div>
<div id="native"></div>
</body>
</html>