Skip to content

Instantly share code, notes, and snippets.

@jcreamer898
Created August 1, 2012 16:10
Show Gist options
  • Save jcreamer898/3228292 to your computer and use it in GitHub Desktop.
Save jcreamer898/3228292 to your computer and use it in GitHub Desktop.
Using mousemove to create regions to trigger a scroll.
_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