简体   繁体   English

EaselJS拖拽:获取抓取位置

[英]EaselJS Drag-Drop: Get Grabbing Position

I'd like to drag-drop a container element with easeljs. 我想用easeljs拖放一个容器元素。 By default event.stageX/stageY refers to the center of the shape or container. 默认情况下,event.stageX / stageY指的是形状或容器的中心。 That means that large elements are centered at mouse position, doesn't matter, whether I grab them at the top-left or bottom-right corner. 这意味着大型元素以鼠标位置为中心,无关紧要,我是否在左上角或右下角抓住它们。

I'd like to have the element bound to the exact mouse position. 我想将元素绑定到精确的鼠标位置。

Sorry for my bad English, it's not my mother tongue. 抱歉我的英语不好,这不是我的母语。

Maybe it's too late but hope this helps. 也许现在为时已晚,但希望这会有所帮助。

container.on('mousedown', function(e){
        var posX = e.stageX;
        var posY = e.stageY;
        this.offset = {x: this.x - posX, y: this.y - posY};
}
container.on('pressmove', function(e){
    var posX = e.stageX;
    var posY = e.stageY;
    this.x = posX + this.offset.x;
    this.y = posY + this.offset.y;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM