问题描述
我在页面底部的position: fixed
工具栏中使用jQuery UI的datepicker控件.有时,在随机计算机上,日期选择器会出现在工具栏下方,这意味着它不在页面上并且无法查看或与之交互.
I'm using jQuery UI's datepicker control in a position: fixed
toolbar at the bottom of my page. Occasionally, on random computers, the datepicker appears below the toolbar, which means it's off the page and impossible to view or interact with.
是否有一种方法可以强制datepicker控件始终位于其<input>
的上方和右侧?
Is there a way to force the positioning of the datepicker control to always be above and to the right of its <input>
?
推荐答案
您可以更改以下行:
offset.left -= (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? Math.abs(offset.left + dpWidth - viewWidth) : 0;
offset.top -= (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? Math.abs(offset.top + dpHeight + inputHeight*2 - viewHeight) : 0;
...阅读:
offset.left = $(inst.input).position().left + dpWidth;
offset.top = $(inst.input).position().top - dpHeight;
但是,这失去了灵活性.如果您的输入恰好位于页面顶部,那么您将遇到与以前相反的问题.
This loses flexibility, though. If your input happens to be at the top of the page, you'll have the opposite problem from before.
这篇关于使jQuery UI的日期选择器始终向某个方向打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!