Skip to content

Instantly share code, notes, and snippets.

@yoko
Created February 24, 2011 04:46
Show Gist options
  • Save yoko/841770 to your computer and use it in GitHub Desktop.
Save yoko/841770 to your computer and use it in GitHub Desktop.
using with onscroll, onresize etc.
(function(ns) {
ns.rarely = rarely();
function rarely() {
var timer = null;
return rarely;
function rarely(f, every) {
every = every || 100;
if (!timer) {
f();
timer = setTimeout(function() {
f();
timer = null;
}, every);
}
}
}
})(this);
@yoko
Copy link
Author

yoko commented Mar 1, 2011

$(document).scroll(function() {
    rarely(function() {
        console.log('call!');
    }, 500);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment