Skip to content

introduced handling of mouse wheel events for scrolling #377

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions src/js/jquery.swipebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@
$.swipebox.extend = function () {
return ui;
};

// This function checks if the specified event is supported by the browser.
// Source: http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
function isEventSupported(eventName) {
var el = document.createElement('div');
eventName = 'on' + eventName;
var isSupported = (eventName in el);
if (!isSupported) {
el.setAttribute(eventName, 'return;');
isSupported = typeof el[eventName] == 'function';
}
el = null;
return isSupported;
}

plugin.init = function() {

Expand Down Expand Up @@ -194,6 +208,7 @@

// Devices can have both touch and keyboard input so always allow key events
$this.keyboard();
$this.mouse();

$this.animBars();
$this.resize();
Expand Down Expand Up @@ -553,6 +568,33 @@
} );
},

/**
* Mouse navigation
*/
mouse : function () {
var wheelEvent = isEventSupported('mousewheel') ? 'mousewheel' : 'wheel';
var $this = this;
$( window ).bind( wheelEvent, function( event ) {
event.preventDefault();
//event.stopPropagation();

var oEvent = event.originalEvent;
var delta = oEvent.deltaY || oEvent.wheelDelta;

// deltaY for wheel event
// wheelData for mousewheel event

if (delta > 0) {
// Scrolled up
$this.getNext();
} else if (delta < 0) {
// Scrolled down
$this.getPrev();
}

} );
},

/**
* Navigation events : go to next slide, go to prevous slide and close
*/
Expand Down Expand Up @@ -920,6 +962,9 @@
*/
destroy : function () {
$( window ).unbind( 'keyup' );
// need to check which event to unbind the same way as having binded it
var wheelEvent = isEventSupported('mousewheel') ? 'mousewheel' : 'wheel';
$( window ).unbind( wheelEvent );
$( 'body' ).unbind( 'touchstart' );
$( 'body' ).unbind( 'touchmove' );
$( 'body' ).unbind( 'touchend' );
Expand Down