Skip to content

Instantly share code, notes, and snippets.

@lusareal
Created August 21, 2018 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lusareal/77bfed655748f359b5f394230e6e4df0 to your computer and use it in GitHub Desktop.
Save lusareal/77bfed655748f359b5f394230e6e4df0 to your computer and use it in GitHub Desktop.
// умное позиционирование
var win = $(window);
var topOffset = selectbox.offset().top;
var bottomOffset = win.height() - selectHeight - (topOffset - win.scrollTop());
var visible = opt.selectVisibleOptions;
var minHeight = liHeight * 6;
var newHeight = liHeight * visible;
if (visible > 0 && visible < 6) minHeight = newHeight;
// раскрытие вверх
if (bottomOffset < 0 || bottomOffset < minHeight) {
dropdown.height('auto').css({top: 'auto', bottom: position});
if (dropdown.outerHeight() > topOffset - win.scrollTop() - 20 ) {
dropdown.height(Math.floor((topOffset - win.scrollTop() - 20) / liHeight) * liHeight);
if (visible > 0 && visible < 6) {
if (dropdown.height() > minHeight) dropdown.height(minHeight);
} else if (visible > 6) {
if (dropdown.height() > newHeight) dropdown.height(newHeight);
}
}
// раскрытие вниз
} else if (bottomOffset > minHeight) {
dropdown.height('auto').css({bottom: 'auto', top: position});
if (dropdown.outerHeight() > bottomOffset - 20 ) {
dropdown.height(Math.floor((bottomOffset - 20) / liHeight) * liHeight);
if (visible > 0 && visible < 6) {
if (dropdown.height() > minHeight) dropdown.height(minHeight);
} else if (visible > 6) {
if (dropdown.height() > newHeight) dropdown.height(newHeight);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment