Initial position
See original GitHub issueI’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:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@outOFFspace
movable 0.10.0 is released.
Try it like this:
thank you 😃
I’m not sure is it a good solution, but setting
left
andtop
CSS attributes as the initial position works for me.I use it this way: