I'm just wondering if there is a way to condense this script? My JS is pretty rough, but it seems like I should be able to just insert an or operator to add the class of shrink to any class that passes, I can't seem to get the syntax correct though. It just seems like a lot of redundancy.
$(window).scroll(function() {
if ($(document).scrollTop() > 50) {
$('nav').addClass('shrink');
} else {
$('nav').removeClass('shrink');
}
if ($(document).scrollTop() > 50) {
$('.nav a').addClass('shrink');
} else {
$('.nav a').removeClass('shrink');
}
if ($(document).scrollTop() > 50) {
$('.navbar-brand').addClass('shrink');
} else {
$('.navbar-brand').removeClass('shrink');
}
});
Or is there a way to add a class to all children of a given element?