Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么捕获属性x,y的变化? #306

Open
1L2018 opened this issue Dec 25, 2024 · 4 comments
Open

怎么捕获属性x,y的变化? #306

1L2018 opened this issue Dec 25, 2024 · 4 comments

Comments

@1L2018
Copy link

1L2018 commented Dec 25, 2024

最近想同步dom元素和canvas元素的位置,在拖动的时候发现leafer-x-snap会造成dom元素canvas对应元素的位置不一致,发现leafer-x-snap吸附元素的时候直接使用了类似item.x = item.x - snapXInfo.offset这样的语句而造成EditorMoveEvent、``没触发,PropertyEvent 触发了,但是数据是undefined,后来想个办法是继承`Rect`,重写`set x set y`,也没有生效。我该如何同步两个元素的位置呢?准备做一个能显示gif图像的设计面板

@1L2018 1L2018 changed the title 怎么获得x 怎么捕获属性x,y的变化? Dec 25, 2024
@leaferjs
Copy link
Owner

通过 PropertyEvent 事件监听x,y属性的变化, 再同步给dom元素。

或者去看一下text-editor插件,里面也用到了dom同步的功能。

@1L2018
Copy link
Author

1L2018 commented Dec 25, 2024

this.app.editor.on( PropertyEvent.CHANGE, this.handleEditorProperty.bind(this) );使用这种方式监听Rect.move(x,y),会产生下面的结果。这应该是不正确的吧,我看正常的拖拽事件attrNamexnewValueoldValue都是有数值的
图片

@leaferjs
Copy link
Owner

监听元素,不是监听editor

@1L2018
Copy link
Author

1L2018 commented Dec 26, 2024

text-editor是一个非常好的dom同步方案,已经采用与text-editor同样的方案来做dom同步。
另外建议给UI(Rect.....)子类的origin的默认值赋值为center,虽然旋转的表现是按照center进行的,但是通过this.editor.element获取到的origin是<empty string>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants