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

Issue with Editor Resizing Not Centered on Mouse Position #476

Open
sonlia opened this issue May 27, 2024 · 2 comments
Open

Issue with Editor Resizing Not Centered on Mouse Position #476

sonlia opened this issue May 27, 2024 · 2 comments

Comments

@sonlia
Copy link

sonlia commented May 27, 2024

Hello,

I've encountered an issue where I've placed the editor on the right side of the page. However, when I attempt to zoom in or out, the scaling does not correctly center around the mouse cursor. The canvas has a parent element with relative positioning.

Could you please provide guidance or a solution to ensure that the zoom operation is centered on the mouse position?
教程

Thank you for your assistance.

@atlasan
Copy link
Contributor

atlasan commented May 27, 2024

        // this.setZoom( scale, [ e.localX, e.localY ] );
        // this.ds.changeScale(scale, [e.clientX, e.clientY]);
        
        var rect = e.target.getBoundingClientRect();
        this.setZoom( scale, [ e.clientX - rect.left, e.clientY - rect.top ] );

this.ds.changeScale(scale, [e.clientX, e.clientY]);

Probably it needs to be implemented inside the DragAndScape, but the above code could work

@sonlia if you can test it and make a PR in case

@sonlia
Copy link
Author

sonlia commented May 30, 2024

Hello, it seems that using this.ds.changeScale(scale, [ e.clientX - rect.left, e.clientY - rect.top ]); also works, but I haven't conducted a complete test yet.

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