Moveable: Resizable - centers

Created on 26 Aug 2019  路  7Comments  路  Source: daybrush/moveable

if you resize from left, right, top or bottom, it does a center resize. Moving both right and left or top and bottom.
Other libs. resize by only moving the side you have clicked on and keeping the others in place.
( hope it make sence :-/ )

question solved

All 7 comments

@Minimalpris
Please refer to the link below.
https://github.com/daybrush/moveable/issues/19

on("resize", ({ direction, delta }) => {
    width += delta;
    height += delta;
    left += direction[0] < 0 ? delta[0] : 0;
    top += direction[1] < 0 ? delta[1] : 0;
});

I've done what you've suggested but now I'm facing a weird resizing behavior when element was rotated. Sorry for asking it here but I think it would be helpful for other people too.

Here is codesandbox with the issue: https://codesandbox.io/s/nice-khayyam-jl3l7

Try to rotate the element and then resize it.

Would be great if you could point out what is going wrong there.

P. S. Thank you for your hard work.

@n3gotium

Try the following:

// from
const { top, left } = target.getBoundingClientRect();
// to
const { top, left } = transformProps;

@daybrush It worked! Thanks a lot for your help!

Can you help me with OnScaleGroup? The scale currently gets applied on every direction however I want it to be like sketch. Unfortunately, I can't get it to work.

@LCGijs

Thank you for feature request.

Please refer to the link below.
https://github.com/daybrush/moveable/issues/41

@LCGijs

moveable 0.9.0 is released.
react-moveable 0.12.1 is released.
preact-moveable 0.11.2 is released.
ngx-moveable 0.5.1 is released.

https://github.com/daybrush/moveable/blob/master/handbook/handbook.md#toc-resizable

import Moveable from "moveable";

const moveable = new Moveable(document.body, {
    target: document.querySelector(".target"),
    resizable: true,
});

const frame = {
    translate: [0, 0],
};
moveable.on("resizeStart", ({ set, setOrigin, dragStart }) => {
    // Set origin if transform-orgin use %.
    setOrigin(["%", "%"]);

    // If cssSize and offsetSize are different, set cssSize. (no box-sizing)
    const style = window.getComputedStyle(ev.target);
    const cssWidth = parseFloat(style.width);
    const cssHeight = parseFloat(style.height);
    set([cssWidth, cssHeight]);

    // If a drag event has already occurred, there is no dragStart.
    dragStart && dragStart.set(frame.translate);
}).on("resize", ({ target, width, height, drag }) => {
    target.style.width = `${width}px`;
    target.style.height = `${height}px`;

    // get drag event
    frame.translate = drag.beforeTranslate;
    target.style.transform
        = `translate(${drag.beforeTranslate[0]}px, ${drag.beforeTranslate[1]}px)`;
}).on("resizeEnd", ({ target, isDrag, clientX, clientY }) => {
    console.log("onResizeEnd", target, isDrag);
});

Thank you :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

probil picture probil  路  4Comments

jiseopX picture jiseopX  路  4Comments

pistell picture pistell  路  4Comments

adityakrshnn picture adityakrshnn  路  4Comments

plotpoi picture plotpoi  路  4Comments