Permalink
Browse files

fixed dropdown placement

  • Loading branch information...
1 parent 92f2a51 commit 007d142aeed49aee357e6b8e965d4fce8f451075 FezVrasta committed Nov 14, 2014
Showing with 9 additions and 6 deletions.
  1. +9 −6 jquery.dropdown.js
View
@@ -141,15 +141,18 @@
selectOptions.each(function() { $(this).attr("tabindex", 0); });
// Set height of the dropdown
- var windowH = $(window).height(),
- scrollTop = $(window).scrollTop(),
- offset = $(this).offset();
+ var coords = {
+ top: $(this).offset().top - $(document).scrollTop(),
+ left: $(this).offset().left - $(document).scrollLeft(),
+ bottom: $(window).height() - ($(this).offset().top - $(document).scrollTop()),
+ right: $(window).width() - ($(this).offset().left - $(document).scrollLeft())
+ };
- var height = windowH - offset.top;
+ var height = coords.bottom;
// Decide if place the dropdown below or above the input
- if (height < 80 && windowH > (offset.top - scrollTop)) {
- height = offset.top - scrollTop;
+ if (height < 200 && coords.top > coords.bottom) {
+ height = coords.top;
$ul.attr("placement", "top-left");
} else {
$ul.attr("placement", "bottom-left");

0 comments on commit 007d142

Please sign in to comment.