jQuery UI 对话框:如果对话框高度大于窗口高度,则垂直滚动工作不正确
这是代码:
<script type="text/javascript">
$(function(){
var dialogOptions = {
title: "Header",
autoOpen: false,
modal: true,
width: 400,
height: 1000
};
$(".wnd").dialog(dialogOptions);
$("#btn").click(function(){ $(".wnd").dialog("open"); });
});
</script>
<style>
.wnd {background:yellow;height:900px;width:300px;}
</style>
<div class="wnd"></div>
<button id="btn">click me</button>
当对话框打开并且它高于主窗口时,有一个侧面滑块,如果您尝试借助鼠标光标拖动它,它不会向下滑动(看起来像是锁定的)。
但当按下键盘上的按钮(箭头)或用鼠标滚轮向下滚动时,它会滑动得很好。
如何激活侧面滑块?
谢谢!
Here is code:
<script type="text/javascript">
$(function(){
var dialogOptions = {
title: "Header",
autoOpen: false,
modal: true,
width: 400,
height: 1000
};
$(".wnd").dialog(dialogOptions);
$("#btn").click(function(){ $(".wnd").dialog("open"); });
});
</script>
<style>
.wnd {background:yellow;height:900px;width:300px;}
</style>
<div class="wnd"></div>
<button id="btn">click me</button>
When dialog is opened and it higher than main window there is a side slider and it doesn't slide down if you try to drag it with the help of mouse cursor (it seemes like locked).
But it slides fine when to put down button (arrow) on keyboard or scroll down with mouse wheel.
Here is demo on jsfiddle.
How to activate that side slider?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个干净的解决方案如下:
http://jsfiddle.net/4fc33/6/
什么我正在做的是包装 jQuery UI 覆盖创建方法来关闭阻止滚动正常工作的事件。
A clean solution would be like this one:
http://jsfiddle.net/4fc33/6/
What I'm doing is wraping the jQuery UI overlay create method to turn off the event that prevents scrolling to work correctly.
无法使用窗口滑块的另一种方法是在对话框窗口本身上启用滑块。如果您对对话框的最大高度设置上限,这些将自动显示,但对于某些版本的 jQueryUI 来说可能有点棘手。
至少在我使用的 jQueryUI 版本 (1.9) 上,我需要自己指定最大高度,因为 maxHeight 属性应该能够根据 文档不起作用*。
这是有效的:
我从窗口高度中减去 120 像素,以适应对话框窗口的页眉和页脚部分及其“确定”按钮。
* 如果尝试调整对话框的大小,最大高度实际上会生效——但不会在显示时生效。
An alternative approach to not being able to use the window's sliders is to enable sliders on the dialog window, itself. These will show up automatically if you place a cap on the maximum height of the dialog but can be a little tricky with some versions of jQueryUI.
At least on the version of jQueryUI that I am on (1.9) I needed to specify the maximum height on my own because the maxHeight property that should be able to be used according to the documentation didn't work*.
Here's what worked:
I subtracted 120 pixels off of the window's height to accommodate for the Dialog window's header -- and footer section with its "ok" button.
* The max-height actually would take affect if the dialog was attempted to be resized -- but not upon display.