[英]Dropdown Select causing auto scroll horizontally
I have a div and a table. 我有一个div和一张桌子。 Inside div there are dropdowns. 里面的div有下拉菜单。 div can be scrolled horizontally. div可以水平滚动。 I've used following tool for the dropdown. 我使用了以下工具进行下拉菜单。
Now here is a piece of it. 现在这里有一块。
In image 1 you can see I've taken the horizontal scroll to the end of it. 在图像1中,您可以看到我已经将水平滚动到了它的末尾。 Now I've selected a dropdown and look what happened. 现在我选择了一个下拉列表,看看发生了什么。
Image 2 is the result. 图2是结果。 The horizontal bar came to the beginning of it. 横杠开始了。 I don't want that. 我不希望这样。 I want the bar to be placed exactly where it was before the selection. 我希望将条形图放置在选择之前的确切位置。 This horizontal bar is inside a div with width:200%
and main body is width:100%
此水平条位于div内 , width:200%
, 主体 width:100%
Code for one dropdown: 一个下拉列表的代码:
<select data-placeholder="" class="chzn_class eighty_percent" name="currency_id_1" id="currency_id_1">
<option value=""></option>
<option value="0">None</option>
</select>
Can anyone please tell me what is wrong? 谁能告诉我有什么问题? How can I fix this? 我怎样才能解决这个问题?
Based on your fiddle I noticed if I removed the disable search setting from initialising javascript then the problem goes away. 基于你的小提琴,我注意到如果我从初始化javascript中删除了禁用搜索设置,那么问题就会消失。
$('.chosen-select').chosen();
But this presents a new problem the search box is shown! 但这显示了搜索框显示的新问题! So a little css can be used to hide the search box. 因此可以使用一点css来隐藏搜索框。
.chosen-search { display: none; }
I've never used harvesthq but I've guessed that the option hides the search feature when there are less that the given number (10 in your case). 我从来没有使用过harvesthq,但是我猜测该选项会在给定数量少于你的情况下隐藏搜索功能(在你的情况下为10)。
So perhaps to replicate this feature you could not hardcode the above css but instead dynamically hide the search box using javascript. 因此,为了复制此功能, 您无法对上述css进行硬编码,而是使用javascript 动态隐藏搜索框 。 ie test number of option
elements, then find the .chosen-search
element and .hide()
it. 即测试option
元素的数量,然后找到.chosen-search
元素和.chosen-search
.hide()
它。
So don't include the style .chosen-search { display: none; }
所以不要包括样式.chosen-search { display: none; }
.chosen-search { display: none; }
and use this: .chosen-search { display: none; }
并使用此:
$('.chosen-select').chosen();
var disable_search_threshold = 10;
$('.chosen-select').each(function (index, element) {
var $select = $(element);
if ($select.find('option').length < disable_search_threshold) {
$select.next('div').find('.chosen-search').hide();
}
});
Just try adding overflow-y:hidden; 只需尝试添加overflow-y:hidden; property and make width:100%. 属性和宽度:100%。 If that doesn't work, try removing the width and height property and adding overflow:scroll; 如果这不起作用,请尝试删除width和height属性并添加overflow:scroll; property to div. 财产到div。
If you provide jsfiddle reference, i can help better. 如果你提供jsfiddle参考,我可以帮助更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.