如何强制 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);
}
});
最佳答案
这对我有用:
$.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
关于jquery - select2 - 始终下拉而不是下拉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32328691/