jQuery UI 对话框:如果对话框高度大于窗口高度,则垂直滚动工作不正确

发布于 2024-12-22 21:47:36 字数 806 浏览 0 评论 0原文

这是代码:

<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>

当对话框打开并且它高于主窗口时,有一个侧面滑块,如果您尝试借助鼠标光标拖动它,它不会向下滑动(看起来像是锁定的)。

但当按下键盘上的按钮(箭头)或用鼠标滚轮向下滚动时,它会滑动得很好。

这是jsfiddle 上的演示

如何激活侧面滑块?

谢谢!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

习ぎ惯性依靠 2024-12-29 21:47:36

一个干净的解决方案如下:

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.

零時差 2024-12-29 21:47:36

无法使用窗口滑块的另一种方法是在对话框窗口本身上启用滑块。如果您对对话框的最大高度设置上限,这些将自动显示,但对于某些版本的 jQueryUI 来说可能有点棘手。

至少在我使用的 jQueryUI 版本 (1.9) 上,我需要自己指定最大高度,因为 maxHeight 属性应该能够根据 文档不起作用*。

这是有效的:

$("#dialog").dialog({
    modal: true,
    width: "auto",
    height: "auto"
    /* maxHeight: whatever won't work, */
}).css("maxHeight", window.innerHeight-120);

我从窗口高度中减去 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:

$("#dialog").dialog({
    modal: true,
    width: "auto",
    height: "auto"
    /* maxHeight: whatever won't work, */
}).css("maxHeight", window.innerHeight-120);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文