question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG/Question] when item is rotated, left & top is calculated incorrectly

See original GitHub issue

Environments

  • Framework name: vanilla
  • Framework version: latest
  • Moveable Component version:
  • Testable Address(optional):

Description

am not really sure if this is intended or is a bug but when item is rotated, the left/top should be the same as the normal

  • rotated remo

  • normal ScreenFlow

  • code

let rotate = 0
let movable = new Moveable(document.querySelector('product'), {
    target      : document.querySelector('logo'),
    dragArea    : true,
    draggable   : true,
    throttleDrag: 0,

    rotatable     : true,
    throttleRotate: 5,

    resizable     : true,
    throttleResize: 0,
    keepRatio     : true,
    baseDirection : [1, 1],

    pinchable     : true,
    pinchThreshold: 20,
    origin        : false,
    edge          : false,

    snappable         : true,
    snapThreshold     : 0,
    snapCenter        : true,
    isDisplaySnapDigit: false,
    elementGuidelines : [document.querySelector('shirt')],
    bounds            : {
                top   : 0,
                bottom: document.querySelector('shirt').clientHeight,
                left  : 0,
                right : document.querySelector('shirt').clientWidth
            }
    })

movable
    .on('drag', ({target, left, top}) => {
        target.style.left = left + 'px'
        target.style.top = top + 'px'
    })
    .on('resize', ({target, width, height, drag}) => {
        target.style.width  = width + 'px'
        target.style.height = height + 'px'
        target.style.left   = drag.left + 'px'
        target.style.top    = drag.top + 'px'
    })
    .on('rotate', ({target, delta}) => {
        let current = rotate + delta

        if (current > 180 || current < -180) {
            return false
        }

        target.style.transform = `rotate(${(Math.round(current))})deg`
    })

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
daybrushcommented, Dec 2, 2020

@ctf0

Whenever rotation is finished, set the bounds like this. Moveable doesn’t support your method. However, you can create a method by setting bounds arbitrarily.

    const containerRect = shirt.getBoundingClientRect();
    const itemRect = logo.getBoundingClientRect();
    const itemStyle = window.getComputedStyle(logo);

    const left = itemRect.left - containerRect.left - parseFloat(itemStyle.left);
    const top = itemRect.top - containerRect.top - parseFloat(itemStyle.top);
   moveable.bounds = {
      left, top, .....
   };
0reactions
ctf0commented, Dec 2, 2020

i’ve updated to the last release & the above snippet is no longer needed, the plugin force that internally, good job @daybrush

however, is there a way to make sure the logo is moved all the way to left while keeping the left/top to 0,0? , here is what i have atm

Screen Shot 2020-12-02 at 10 32 33 PM

note that this only happens if the item have a different width & height aka.not a box.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get elements top and left position after being rotated
This will determine the Y-position of the rotated elements top left corner. Keep in mind that (myElem.outerHeight() / 2) is the transform-origin ...
Read more >
rotate() - CSS: Cascading Style Sheets - MDN Web Docs
The rotate() CSS function defines a transformation that rotates an element around a fixed point on the 2D plane, without deforming it.
Read more >
Chapter 1 Rotation of an Object About a Fixed Axis
ROTATION OF AN OBJECT ABOUT A FIXED AXIS q r s. Figure 1.1: A point on the rotating object is located a distance...
Read more >
How to set a rotated element's base placement in CSS
This property can be used to specify the origin of the rotation of an element. It is the point about which an element...
Read more >
leetcode medium
Search in Rotated Sorted Array. "Two sum", the "Hello World" of coding interviews, was the first problem. We started with casual conversation about...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found