GWT 弹出面板的静态定位

发布于 2024-12-03 21:01:51 字数 882 浏览 1 评论 0原文

我正在使用 GWT 弹出面板来显示 jsp 页面中垂直堆叠的一些信息。我面临的问题是,一旦显示弹出面板,它就不会保持其设置位置。我使用 setPopupPosition() 设置弹出面板的位置。 然而,每当用户滚动浏览器时,显示的弹出面板就会相应地上下移动。它不会保持其显示的原始位置。

我尝试将 css 属性设置为(position:fixed;)应用于弹出面板,但它不起作用。我在某个地方读到,为了静态显示 html 元素,我们可以使用position:fixed和width:100%来实现这一点。但就我而言,我无法将宽度设置为 100%,因为我需要以特定尺寸显示弹出面板。

GWT中有没有办法实现弹出面板的固定位置?我是否必须监听浏览器的滚动条事件才能修复位置,或者可以以不同的方式处理它。

这是我的一段代码,我用它来设置弹出面板在 GWT 中的位置。

           final PopupPanel simplePopup = new PopupPanel(false);
           _beamMenu = simplePopup;
           rendererDisplay(response, simplePopup,true);
           int left =_beamIcon.getAbsoluteLeft() + _beamIcon.getOffsetWidth() - simplePopup.getOffsetWidth();
           int top = _beamIcon.getAbsoluteTop() - simplePopup.getOffsetHeight();
           simplePopup.setPopupPosition(left, top);

在这方面的任何帮助将受到高度赞赏。

非常感谢, 阿希什

I'm using a GWT popup panel for displaying some information stacked up vertically in my jsp page. The problem I'm facing is that, once the popup panel is displayed, it doesn't hold on to its set position. I'm setting the position of the popup panel using setPopupPosition().
However, whenever the user scrolls the browser, the popup panel displayed moves up and down accordingly. It doesn't maintain its original position, where it was displayed.

I've tried setting the css property to (position: fixed;) applied on the popup panel, but it doesn't work. I read someplace, that in order for an html element to be displayed statically, we can use the position: fixed, and width: 100% to achieve that. But in my case, I can't set the width to 100%, since I need the popup panel to be displayed for a specific size.

Is there a way to achieve the fixed position of the popup panel in GWT? Would I have to listen to browser's scrollbar events in order to fix the position or can it be handled differently.

This is my piece of code, which I use to set the popup panel's position in GWT.

           final PopupPanel simplePopup = new PopupPanel(false);
           _beamMenu = simplePopup;
           rendererDisplay(response, simplePopup,true);
           int left =_beamIcon.getAbsoluteLeft() + _beamIcon.getOffsetWidth() - simplePopup.getOffsetWidth();
           int top = _beamIcon.getAbsoluteTop() - simplePopup.getOffsetHeight();
           simplePopup.setPopupPosition(left, top);

Any help in this regard will be highly appreciated.

Many thanks,
Asheesh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

悲欢浪云 2024-12-10 21:01:51

添加一个 css:position:fixed!important;

add a css with: position: fixed !important;

痕至 2024-12-10 21:01:51

PopupPanel 的默认行为应该足够了。您实际上想要位置:绝对而不是固定。 (请参阅 http://www.quirksmode.org/css/position.html 了解位置类型的解释,但固定是指当您滚动时它浮动)。

您可能遇到的问题是,当您显示 PopupPanel 时,它会从 DOM 中的任何位置删除,并添加到 RootPanel 中:(

这是来自 GWT 2.4,因此您的确切代码可能非常)

public void show() {
    if (showing) {
        return;
    } else if (isAttached()) {
        // The popup is attached directly to another panel, so we need to remove
        // it from its parent before showing it. This is a weird use case, but
        // since PopupPanel is a Widget, its legal.
        this.removeFromParent();
    }
    resizeAnimation.setState(true, false);
}

...

public void setState(boolean showing, boolean isUnloading) {
    ...
    RootPanel.get().add(curPanel);
    ...
}

因此,尽管 position:absolute 应该足够了,但您的其他顶级小部件也可能是绝对定位的。因此,当您滚动页面时,您可能实际上正在滚动其他小部件之一的内容,并且 PopupPanel 粘在 到外部元素,该元素没有大的偏移高度,也不是正在滚动。这就是为什么它看起来具有与使用固定定位相同的行为(即始终距浏览器窗口顶部和侧面 XX 像素)。

返回并查看您的页面构造并修复其他小部件,您应该没问题。根据我的观察,新的 LayoutPanel 到处都使用 position:absolute,因此您可能需要手动将其设置为 relative

The default behavior of the PopupPanel should be enough. You actually want position: absolute and not fixed. (See http://www.quirksmode.org/css/position.html for an explanation of position types, but fixed is when it appears to float as you scroll).

The issue you are likely running into, is that when you show the PopupPanel, it gets removed from wherever it was in the DOM, and added to the RootPanel:

(This is from GWT 2.4 so your exact code may very)

public void show() {
    if (showing) {
        return;
    } else if (isAttached()) {
        // The popup is attached directly to another panel, so we need to remove
        // it from its parent before showing it. This is a weird use case, but
        // since PopupPanel is a Widget, its legal.
        this.removeFromParent();
    }
    resizeAnimation.setState(true, false);
}

...

public void setState(boolean showing, boolean isUnloading) {
    ...
    RootPanel.get().add(curPanel);
    ...
}

As a result, though the position: absolute should be enough, likely your other top level Widgets are also absolutely positioned. Therefore, when you scroll the page you are likely actually scrolling the contents of one of your other widgets, and the PopupPanel is stuck to the outer element, which does not have a large offset-height and is not being scrolled. This is why it appears to have the same behavior as if it were using fixed positioning (i.e. always XX pixels from the top and side of the browser window).

Go back and look at your page construction and fix the other Widgets and you should be fine. From my observations, the new LayoutPanels use position: absolute all over the place, so you may have to manually set it to relative.

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