Created
August 1, 2012 16:10
-
-
Save jcreamer898/3228292 to your computer and use it in GitHub Desktop.
Using mousemove to create regions to trigger a scroll.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_setupEvents: function() { | |
this.$el.on( "click", "a.detail-content-trigger", this.openYear ); | |
this.$el.on( "mousemove", _.throttle(this._checkMouse, 500)); | |
}, | |
_checkMouse: function( event ) { | |
var winWidth = $( window ).width(), | |
// Define some regions of the screen to toggle left and right scrolling. | |
screenRegions = { | |
Left: "0 300", | |
Middle: "300 " + (winWidth - 300), | |
Right: (winWidth - 300) + " " + winWidth | |
}, | |
// Get the active mouse position. | |
mouseX = event.clientX, | |
high, low, region; | |
region = _.reduce(screenRegions, function(memo, region, name) { | |
low = region.split(" ")[0]; | |
high = region.split(" ")[1]; | |
if ( mouseX > low && mouseX < high ) { | |
memo = name; | |
} | |
return memo; | |
}, ""); | |
if ( region ) { | |
this[ "scroll" + region](); | |
} | |
}, | |
scrollLeft: function() { | |
console.log("Scroll left"); | |
}, | |
scrollRight: function() { | |
console.log("Scroll right"); | |
}, | |
scrollMiddle: function() { | |
console.log("Scroll middle"); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment