T
T
thehighhomie2018-10-01 16:15:37
JavaScript
thehighhomie, 2018-10-01 16:15:37

Algorithm for proportional element resizing?

Good afternoon everyone! Please help me to bring the code to mind: https://jsfiddle.net/7vuwcad1/7/
I wrote the code for resizing the elements, everything worked OK. Now we need to add the ability to resize while maintaining proportions when pressing SHIFT. I was able to achieve a proportional resize, but the element jumps a lot, resize in different ways, it will be seen that the element bounces, moving from the top to the bottom and vice versa.
For simplicity, I added only one button, I need to understand how to write such an algorithm and I can add the rest of the buttons myself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2018-10-01
@thehighhomie

Here is a snippet from my project

if (isProportional) {
                        // Тянем за низ или вверх.
      if (changeHeight) {
        const rh = this.state.startParams.object.height / object.height; // Получаем соотношение начальной высоты к измененной
        object.width = this.state.startParams.object.width / rh; // полученное соотношение применяем для ширины
      } else if (changeWidth) { // Тянем влево или вправо
        const rw = this.state.startParams.object.width / object.width; // Получаем соотношение начальной ширины  к измененной
        object.height = this.state.startParams.object.height / rw; // полученное соотношение применяем для высоты
      }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question