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
I know this is an old question, but it's high up on google results so here's another simple solution that worked for me. Adjust the 150
in the if
statement for however much space your dropdown will need.
var dropUp = function() {
var windowHeight = $(window).innerHeight();
var pageScroll = $('body').scrollTop();
$( ".your-dropdown" ).each( function() {
var offset = $( this ).offset().top;
var space = windowHeight - ( offset - pageScroll );
if( space < 150 ) {
$( this ).addClass( "dropup" );
} else {
$( this ).removeClass( "dropup" );
}
});
}
$(window).load(dropUp);
$(window).bind('resize scroll mousewheel', dropUp);