jquery-ui selectmenu 滚动时出现在屏幕上

jquery-ui selectmenu fix on screen when i scrolling

在我的网站上有一个面板(带有垂直滚动条),元素位于其中。

<div id = 'panel' style = 'width: 200px; height: 600px; overflow-y: scroll;'>
    <select id = 'select-in-panel'></select>
</div>

jquery-ui menuselect 连接到元素。

$('select-in-panel').selectmenu();

当我单击一个项目并展开一个大的下拉列表时,它会随着主 window 而不是面板滚动。

jquery-ui selectmenu 的下拉列表固定在屏幕上,当我滚动面板的滑块(div)时它不会移动,但是它当我滚动主window(正文)中的滑块时移动。在我看来,jquery-ui selectmenu 下拉列表的父级是主window,而不是面板

如何解决?


第二个问题:

如果项目列表很大,我可以设置下拉列表框的最大大小以在此 window 内滚动吗?

现在整个列表显示为一个整体

您可以指定将菜单附加到哪个元素:

$('select-in-panel').selectmenu({
  appendTo: '#panel'
});

您可以设置下拉框的高度,使其在溢出时可以滚动:

$('select-in-panel').selectmenu("menuWidget")
  .addClass('overflow');

然后在你的 css:

.overflow { height: 200px; }

有关更多信息和示例,请参阅文档: http://api.jqueryui.com/selectmenu

另一种通常更简单的处理方法是将 class .ui-front 添加到应该附加 selectmenu 的父级。请注意,此父项 div 将需要 position: relative,因为选择菜单 div 将具有 position: absolute

参见:https://api.jqueryui.com/selectmenu/#option-appendTo

When the value is null, the parents of the are checked for a class name of ui-front. If an element with the ui-front class name is found, the menu is appended to that element. Regardless of the value, if no element is found, the menu is appended to the body.