【发布时间】:2015-09-01 09:57:49
【问题描述】:
如何强制 select2 总是下拉而不是下拉?
我尝试了这个解决方案,但它不起作用:This doesn't work
$("#e1").select2()
.on('select2-open', function() {
// however much room you determine you need to prevent jumping
var requireHeight = 600;
var viewportBottom = $(window).scrollTop() + $(window).height();
// figure out if we need to make changes
if (viewportBottom < requireHeight)
{
// determine how much padding we should add (via marginBottom)
var marginBottom = requireHeight - viewportBottom;
// adding padding so we can scroll down
$(".aLwrElmntOrCntntWrppr").css("marginBottom", marginBottom + "px");
// animate to just above the select2, now with plenty of room below
$('html, body').animate({
scrollTop: $("#e1").offset().top - 10
}, 1000);
}
});
【问题讨论】:
标签: jquery jquery-select2