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.

I’m creating an editor, so I need to load my elements to the page dynamically. So the question is how properly to set up an initial moveable position. By default, all elements are not selected. Vue template:

<template>
    <div
            :id="id"
            :style="{width, height, opacity, transform}"
            :class="['moveable pix-object', {selected}]"
            @mousedown="initMoveable"
            v-click-outside="vcoConfig"
    >
        <slot/>
    </div>
</template>
const frame = {
    translate: [0, 0],
    rotate: 0
};

...
methods: {
    setRotate() {
        const [a, b] = this.matrix
        if (a && b) {
            let radians = Math.atan2(+b, +a)
            if (radians < 0) {
                radians += (2 * Math.PI)
            }
            frame.rotate = radians * (180 / Math.PI)
         }
   },
   setTranslate() {
       const [, , , , tx, ty] = this.matrix
       if (tx && ty) {
           this.$set(frame, 'translate', [+tx, +ty])
       }
    },
    initFrame() {
        this.setRotate()
        this.setTranslate()
    },
    setStyle(target) {
        const {translate: [translateX, translateY], rotate} = frame
        target.style.transform
                    = `translate(${translateX}px, ${translateY}px) rotate(${rotate}deg)`
    },
    initMoveable(e) {
        this.selected = true
        const container = document.getElementById('page-0')
        if (!this.moveable) {
            const {offsetHeight, offsetWidth} = container
            this.moveable = new Moveable(container, {
                ...this.$props,
                verticalGuidelines: [0, offsetHeight / 2, offsetHeight],
                horizontalGuidelines: [0, offsetWidth / 2, offsetWidth],
                target: this.$el,
                container
             })
             this.moveable.dragStart(e)
        } else {
             this.moveable.target = this.$el
             // it doesn't work without a timer
             setTimeout(() => {
                 this.moveable.dragStart(e)
             })
        }
    },
    handleDragStart({set}) {
        set(this.frame.translate)
    },
    handleDrag({target, beforeTranslate}) {
        this.frame.translate = beforeTranslate
        this.setStyle(target)
    },
},
mounted() {
    this.initFrame()
}

The problem is that beforeTranslate is always [0, 0] and handleDragStart never fired if I manually trigger the drag event (dragStart) and the element always moves to the [0, 0].

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
daybrushcommented, Nov 8, 2019

@outOFFspace

movable 0.10.0 is released.

Try it like this:

moveable.setState({
  target: this.$el,
}, () => {
 movable.dragStart(e);
});

thank you 😃

0reactions
osbrecommented, Apr 27, 2021

I’m not sure is it a good solution, but setting left and top CSS attributes as the initial position works for me.

I use it this way:

moveable.on("drag", ({target, left, top, right, bottom}) => {
    target.style.left = `${left}px`;
    target.style.top = `${top}px`;
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Between initial position and final position , displacement is ...
Between initial position and final position , displacement is ……. but distance ………
Read more >
Find Initial Position, Velocity Vector, and Speed ... - YouTube
This video explains how to find the initial position vector, velocity vector, and speed from a given vector ...
Read more >
Vectors How to Find Initial Position and Speed from ... - YouTube
Vectors IB SL Maths Review. Vectors How to Find Initial Position and Speed from Displacement Equation Q1. 2.8K views 5 years ago.
Read more >
Reverso - initial position definition | English definition dictionary
5 tr to sign with one's initials, esp. to indicate approval; endorse (C16: from Latin initialis of the beginning, from initium beginning, literally:...
Read more >
position - CSS: Cascading Style Sheets - MDN Web Docs
The position CSS property sets how an element is positioned in a ... otherwise, it is placed relative to the initial containing block....
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