如何强制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);
}
});
答案 0 :(得分:5)
这对我有用:
$.fn.select2.amd.require([
'select2/selection/multiple',
'select2/selection/search',
'select2/dropdown',
'select2/dropdown/attachContainer',
'select2/dropdown/closeOnSelect',
'select2/utils'
], function (MultipleSelection, Search, Dropdown, AttachContainer, CloseOnSelect, Utils) {
var SelectionAdapter = Utils.Decorate(
MultipleSelection,
Search
);
var DropdownAdapter = Utils.Decorate(
Utils.Decorate(
Dropdown,
CloseOnSelect
),
AttachContainer
);
$('#e1').select2({
dropdownAdapter: DropdownAdapter
});
});
<强> jsFiddle 强>
答案 1 :(得分:1)
我正在使用Select2 v4.0.5(最小版本)
打开select2.js
搜索virtualenv
要始终下拉,请将c?!j&&k&&c&&(e="below"):e="above"
替换为"above"
要始终删除,请将"below"
替换为"below"