我有一个 Ext.Container,我需要向它添加一个用户可移动的对象。
我看到 elsewhere Ext.Window 不应该嵌套到对象中,因此对于其他可移动的 Ext 对象我有什么选择?
问候,卡斯珀
最佳答案
回到这个问题,你的建议一路帮助了我。 面板 的ExtJS 文档建议如何自定义 可拖动 实现。
draggable: {
// Config option of Ext.Panel.DD class.
// It's a floating Panel, so do not show a placeholder proxy in the original position.
insertProxy: false,
// Called for each mousemove event while dragging the DD object.
onDrag : function(e){
// Record the x,y position of the drag proxy so that we can
// position the Panel at end of drag.
var pel = this.proxy.getEl();
this.x = pel.getLeft(true);
this.y = pel.getTop(true);
// Keep the Shadow aligned if there is one.
var s = this.panel.getEl().shadow;
if (s) {
s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
}
},
// Called on the mouseup event.
endDrag : function(e){
this.panel.setPosition(this.x, this.y);
}
}
在我的项目中,我需要容器元素内的可拖动元素,因此我需要做一些额外的事情。
为什么?
因为检索任何位置信息都是在 browser-window-space 中完成的,而设置位置似乎是在 parent-space 中。因此我需要在设置最终面板位置之前转换位置。
// Called on the mouseup event.
endDrag: function (e) {
if (this.panel.ownerCt) {
var parentPosition = this.panel.ownerCt.getPosition();
this.panel.setPosition(this.x - parentPosition[0], this.y - parentPosition[1]);
} else {
this.panel.setPosition(this.x, this.y);
}
}
我希望这可以帮助其他人,再次非常感谢您的投入:)
关于javascript - Extjs 3.x : Can I make a panel or a container movable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3108958/