Try this,
if ((self.offset().top + self.outerHeight(true) + list.outerHeight()) > $(window).height() + $(window).scrollTop()) {
// position the dropdown on top
list.offset({
'left': self.offset().left+self.width() ,
'top': self.offset().top - list.height()+ self.innerHeight()
});
} else {
// put it under the input
list.offset({
'left':self.offset().left +self.width(),
'top': self.offset().top
});
}