Use throttling on our handling of scroll events.

This actually is a bit cleaner than our last approach,
because (I believe) we run our scroll handler code
even after the final scroll event, which prevents the
pointer from getting hidden by rapid scrolls.

(imported from commit 3bde4e8f067cd2406f90c04425c6e4ffb81ea784)
This commit is contained in:
Waseem Daher 2012-10-05 15:35:36 -04:00
parent 8333d44f31
commit 0c3ace82d5
2 changed files with 5 additions and 9 deletions

View File

@ -27,6 +27,7 @@
<script type="text/javascript" src="/static/third/handlebars/handlebars-1.0.rc.1.js"></script>
<script type="text/javascript" src="/static/third/spin/spin.min.js"></script>
<script type="text/javascript" src="/static/third/jquery-mousewheel/jquery.mousewheel.js"></script>
<script type="text/javascript" src="/static/third/jquery-throttle-debounce/jquery.ba-throttle-debounce.min.js"></script>
<script type="text/javascript" src="/static/js/setup.js"></script>
<script type="text/javascript" src="/static/js/dom_access.js"></script>
<script type="text/javascript" src="/static/js/narrow.js"></script>

View File

@ -124,18 +124,13 @@ $(function () {
sub_from_home(compose_class_name(), $('#class-nosub'));
});
var last_mousewheel_or_scroll = 0;
function do_mousewheel_or_scroll () {
var throttled_scrollhandler = $.throttle(50, function() {
if ($('#home').hasClass('active')) {
var time = $.now();
if (time - last_mousewheel_or_scroll > 50) {
keep_pointer_in_view();
last_mousewheel_or_scroll = time;
}
}
}
$(window).mousewheel(do_mousewheel_or_scroll);
$(window).scroll(do_mousewheel_or_scroll);
});
$(window).mousewheel(throttled_scrollhandler);
$(window).scroll(throttled_scrollhandler);
$('#sidebar a[data-toggle="pill"]').on('show', function (e) {
// Save the position of our old tab away, before we switch