Cha*_*hau 1 javascript extjs object movable
我有一个Ext.Container,我需要添加一个用户可移动的对象.
我在其他地方看到Ext.Window不应该嵌套到对象中,因此我对其他可移动Ext对象的选择是什么?
此致,卡斯帕
回到这个问题,你的建议帮助了我.面板的ExtJS文档建议如何执行draggable的自定义实现.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的项目中,我需要在容器元素中使用可拖动元素,因此我需要做一些额外的事情.
为什么?
因为检索任何位置信息是在浏览器窗口空间中完成的,并且设置位置似乎在父空间中.因此,我需要在设置最终面板位置之前转换位置.
// 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);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这可以帮助别人,并再次感谢你的投入:)