将约束窗口相对于约束容器的中心和顶部定位 [英] Position a constrained Window relative from the center and top of the constraining container

查看:128
本文介绍了将约束窗口相对于约束容器的中心和顶部定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要定义一个受限的窗口(像这样示例)相对于容器的顶部和中心限制。但是在配置中,我们只发现x和y需要计算每个文档的中心变化。

We need to position a constrained Window (like in this example) relative from the top and the center of the container where it is constrained to. But in the config we only found x and y which would require to calculate the center on each document change.

没有其他方法存档吗?

推荐答案

你可以使用

alignTo()docs

alignTo(element, [position], [offsets], [animate] )




将元素与另一个对齐元素相对于指定的
锚点。如果另一个元素是文档,它将它对齐到
视口。 position参数是可选的,可以使用以下格式之一指定

Aligns the element with another element relative to the specified anchor points. If the other element is the document it aligns it to the viewport. The position parameter is optional, and can be specified in any one of the following formats:

空白:默认将元素的左上角与
目标左下角(tl-bl)。一个锚(已弃用):
传递的锚位置用作目标元素的锚点。
要对齐的元素将其左上角(tl)定位到
。这种方法已被弃用,有利于下面的较新的两个
锚定语法。两个锚点:如果
下面的两个值通过破折号分隔,则第一个值用作
元素的锚点,第二个值用作目标的
锚点点。除了锚点之外,位置参数
还支持?字符。如果?在
位置字符串的末尾传递,该元素将尝试按照指定进行对齐,但
如果需要
,则该位置将被调整为约束到视口。请注意,正在对齐的元素可能会交换到
对齐到与指定的位置不同的位置,以便执行
视口约束。以下是所有支持的锚点
位置...有关更多信息,请参阅 docs

Blank: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl"). One anchor (deprecated): The passed anchor position is used as the target element's anchor point. The element being aligned will position its top-left corner (tl) to that point. This method has been deprecated in favor of the newer two anchor syntax below. Two anchors: If two values from the table below are passed separated by a dash, the first value is used as the element's anchor point, and the second value is used as the target's anchor point. In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than that specified in order to enforce the viewport constraints. Following are all of the supported anchor positions... for more info see the docs

anchorTo( )docs

anchorTo(element, [position], [offsets], [animate], [monitorScroll], [callback])




将元素固定到另一个元素,并将其重新对齐窗口调整大小。

Anchors an element to another element and realigns it when the window is resized.

编辑

如果您在早期状态下做某事,定位可能会失败。我会尝试通过使用 Ext.Function.createDelayed 。尝试10-50之间的延迟。

If you do something of this in a early state the positioning may fail. I would try to add a delay to the alignment by using Ext.Function.createDelayed. Try something between 10-50 as delay.

示例:

Ext.Function.createDelayed(windowRef.anchorTo,50)(Ext.getBody(),'t-t',[-100,0]);

这篇关于将约束窗口相对于约束容器的中心和顶部定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆