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

Change aspecRatio programmatically. Does not work as expected. #1002

Open
flagsoft opened this issue May 30, 2023 · 0 comments
Open

Change aspecRatio programmatically. Does not work as expected. #1002

flagsoft opened this issue May 30, 2023 · 0 comments

Comments

@flagsoft
Copy link

If you keep a reference to the modifier object, you can call modifier.disable() and modifier.enable(). The enable(); disable() methods aren't documented because I'm still experimenting with them, but they'll probably stay.

const preserveRatio = interact.modifiers.aspectRatio({ ratio: 'preserve', enabled: true })
target.resizable({ modifiers: [preserveRatio] })
///...

preserveRatio.disable()

This does not work as expected. (Or wrong implementation, see code below)

When move around object at non-edges, it also resizes the whole object, which is wrong.
But this should not be the case as it is the default with no aspectRatio modifiers.

var myPreserveRatio = interact.modifiers.aspectRatio({ ratio: 'preserve', enabled: false })

var myInteract = interact('.grid_snap')

listeners: {
                    move (event) {
                        var target = event.target

          // I want to add here: When SHIFT-key pressed, set modifier as aspectRatio enabled.
          if ( SHIFT key pressed) {
               myPreserveRatio.enable()
          } else {
               myPreserveRatio.disable()
         }

modifiers: [
                    // minimum size, status:works
                    interact.modifiers.restrictSize({
                        min: { width: 10, height: 10 }
                    }),
                    
                    myPreserveRatio
],

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

1 participant