Created
August 21, 2018 13:14
-
-
Save lusareal/77bfed655748f359b5f394230e6e4df0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// умное позиционирование | |
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