我们需要相对于容器的顶部和中心定位一个受约束的窗口(如 example )。但在配置中我们只找到了 x 和 y,这需要计算每个文档更改的中心。
没有其他方法可以存档吗?
最佳答案
你可以使用
alignTo(element, [position], [offsets], [animate] )
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:
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(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 之间的延迟。
示例:
Ext.Function.createDelayed(windowRef.anchorTo,50)(Ext.getBody(),'t-t',[-100,0]);
关于extjs - 相对于约束容器的中心和顶部定位受约束窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20074598/