As far as I can see, building a custom select box is somehow problematic on web clients.
(据我所知,在Web客户端上构建自定义选择框存在某种问题。)
It basically boils down to 2 options at high level:(从根本上讲,它大致可以归结为2个选项:)
- Append the options dropdown to the element itself.
(将选项下拉列表附加到元素本身。)
In this case, if a parent of the select box has overflow: hidden
, dropdown will be clipped if it overflows.(在这种情况下,如果选择框的父级具有overflow: hidden
,则下拉菜单将在溢出时被剪切。)
- Append the options dropdown to body, in this case, parents having
overflow: hidden
won't be a problem, but we'd need to track multiple events that could change the position/size of the select element (scrolling, this could be any parent element of the select box, resizing, select element getting hidden inside a scrollable element etc.), and this seems both difficult to manage and as many things need to be tracked real time, can cause performance issues.(将选项下拉列表附加到正文,在这种情况下,父母有overflow: hidden
不会有问题,但是我们需要跟踪多个事件,这些事件可能会更改select元素的位置/大小(滚动,可以是任何选择框的父元素,调整大小,将选择元素隐藏在可滚动元素内等),这似乎既难以管理,又需要实时跟踪许多内容,可能会导致性能问题。)
My question is, with the latest state of html / css / javascript supported by browsers, is there a new way to handle these problems, that weren't available before?
(我的问题是,由于浏览器支持html / css / javascript的最新状态,是否有新方法来处理这些以前没有的问题?)
Or maybe there is another option than the ones I pointed out above.(也许除了我上面指出的以外,还有其他选择。)
Fiddle explaining the two cases
(小提琴解释这两种情况)
ask by Ozgur Akcali translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…