Intentalo con esta funcion debounce
. Algo asi:
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
$(window).scroll(debounce(function() {
var scroll = $(window).scrollTop();
//>=, not <=
if (scroll >= 50) {
//clearHeader, not clearheader - caps H
$(".navbar-brand").addClass("navbar-shrink");
$(".navbar").addClass("nav-shrink");
$(".logo-navbar").addClass("img-shrink");
}
else{
$(".logo-navbar").removeClass("img-shrink");
$(".navbar").removeClass("nav-shrink");
$(".navbar-brand").removeClass("navbar-shrink");
}
}, 25));