Created
January 6, 2015 22:05
-
-
Save tomleo/b6823624bc77b7b78a5f to your computer and use it in GitHub Desktop.
Efficient scroll function using setInterval
This file contains 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
$.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