Created
October 26, 2012 06:44
-
-
Save sunng87/3957289 to your computer and use it in GitHub Desktop.
Hacking mouse scrolling
This file contains hidden or 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
var mousewheel_buffer = []; | |
var mousewheel_buffer_size = 5; | |
$(document).mousewheel(function(e, d){ | |
// not for landing page | |
if (!app.current_timeline) { | |
return true; | |
} | |
if (mousewheel_buffer.length === mousewheel_buffer_size) { | |
mousewheel_buffer.shift(); | |
} | |
mousewheel_buffer.push(new Date().getTime() * (d > 0 ? 1: -1)); | |
if (mousewheel_buffer.length >= mousewheel_buffer_size | |
&& _.all(mousewheel_buffer, function(i){ return i>0 }) | |
&& ( _.last(mousewheel_buffer) - _.first(mousewheel_buffer)) < 1000) { | |
mousewheel_buffer = []; | |
// actual up | |
app._on_prev(); | |
} | |
if (mousewheel_buffer.length >= mousewheel_buffer_size | |
&& _.all(mousewheel_buffer, function(i){ return i<0 }) | |
&& (_.last(mousewheel_buffer) - _.first(mousewheel_buffer)) > -1000) { | |
mousewheel_buffer = []; | |
// actual down | |
app._on_next(); | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment