I was wondering if any of you has what I am asking for ready, to save me from the trouble. What I am looking for is for a dropdown menu to have the dropup class automatically ad
Edit 07 Jan 2019: tidied up the variable names and optimized the code just a bit.
dropup = function() {
$(".dropdown-toggle").each(function(){
offsetTop=$(this).offset().top+$(this).height()-$(window).scrollTop();
offsetBottom=$(window).height()-$(this).height()-$(this).offset().top+$(window).scrollTop();
ulHeight=$(this).parents('.btn-group').find('ul').height();
if ((offsetBottom < ulHeight) && (offsetTop > ulHeight)) {
parent.addClass('dropup');
} else {
parent.removeClass('dropup');
}
});
}
$(window).on('load resize scroll', dropup);