如何在移动 safari 上获得以用户当前视图端口为中心的 GWT PopupPanel?

发布于 2024-11-19 21:45:45 字数 71 浏览 3 评论 0原文

调用 .center() 使面板在整个页面上居中。我想让它位于当前视图端口的正中心...另外我想防止滚动..但也许我会回到那个。

calling .center() makes the panel center on the entire page.. I'd like to have it dead center of the current view port... additionally I'd like to prevent scrolling.. but maybe I'll come back to that one.

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

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

发布评论

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

评论(2

唔猫 2024-11-26 21:45:45

留出死点给用户练习,但关键组件是 Window.getScrollTop() 和 Window.getScrollLeft()

Dead center is left for an exercise for the user, but the key component is Window.getScrollTop() and Window.getScrollLeft()

娇柔作态 2024-11-26 21:45:45

标准 center() 方法不能满足您的要求。所以你必须自己计算位置。有一个大问题是您的弹出窗口在实际显示之前没有尺寸。任何 DOM 元素的大小在完全附加到 DOM 之前都无法查询。您必须继承 GWT 弹出窗口类并重写 onLoad() 方法才能获取弹出窗口的大小。尝试这样的事情:

public class CenteredDialogBox extends DialogBox {

    private Widget _parent;

    public CenteredDialogBox(Widget parent) {
        _parent = parent;
    }

    @Override
    public void onLoad() {
        super.onLoad();

        int parentMiddle = _parent.getAbsoluteLeft() + _parent.getOffsetWidth() / 2;
        int popupLeft = parentMiddle - getOffsetWidth() / 2;
        int parentCenter = _parent.getAbsoluteTop() + _parent.getOffsetHeight() / 2;
        int popupTop = parentCenter - getOffsetHeight() / 2;

        setPopupPosition(popupLeft, popupTop);
    }

}

The standard center() method does not do what you want. So you have to calculate the position yourself. There is one big problem that is your popup does not have a size before it is actually shown. The size of any DOM element can not be queried until it is fully attached to the DOM. You have to inherit the GWT popup class and overriding the onLoad() method to get the size of the popup. Try something like this:

public class CenteredDialogBox extends DialogBox {

    private Widget _parent;

    public CenteredDialogBox(Widget parent) {
        _parent = parent;
    }

    @Override
    public void onLoad() {
        super.onLoad();

        int parentMiddle = _parent.getAbsoluteLeft() + _parent.getOffsetWidth() / 2;
        int popupLeft = parentMiddle - getOffsetWidth() / 2;
        int parentCenter = _parent.getAbsoluteTop() + _parent.getOffsetHeight() / 2;
        int popupTop = parentCenter - getOffsetHeight() / 2;

        setPopupPosition(popupLeft, popupTop);
    }

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