Skip to content

Instantly share code, notes, and snippets.

@tomleo
Created January 6, 2015 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomleo/b6823624bc77b7b78a5f to your computer and use it in GitHub Desktop.
Save tomleo/b6823624bc77b7b78a5f to your computer and use it in GitHub Desktop.
Efficient scroll function using setInterval
$.fn.scrollFoo = function() {
'use strict'
var that = this,
didscroll = false;
$(window).scroll(function() {
didscroll = true;
});
setInterval(function() {
if(didscroll) {
$(that).each(function(index, that) {
var sT = $(window).scrollTop();
if (sT < 450) {
$(that).velocity();
} else {
$(that).velocity();
}
});
}
}, 500); //.5ms poll speed (250 is very commmon in other libs)
};
$('#baz').scrollFoo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment