Scrollen mit timeout

by shapeshifta

HTML

<div id="foo"></div>

CSS

body {height:1000px}
#foo {position:fixed;top:0;left:0}

JavaScript

var counter = 0,
    timer = 0,
    foo = function() {
        $('#foo').html(counter++ + ' mal gescrollt');
    };

$(window).scroll(function() {
    if (timer) {
        clearTimeout(timer);
    }

    // Use a buffer so we don't call foo too often. 
    timer = setTimeout(foo, 100);
});