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.

moveable position is wrong

See original GitHub issue

Environments

  • Framework name: vue3-moveable
  • Framework version: 0.1.0
  • Moveable Component version:
  • Testable Address(optional):

Description

image

<div ref="panelContainerRef" class="panel-container"  style="position: relative; left: 0; top: 0">
            <div
              ref="panelCanvasRef"
              style="position: relative"
            >
              <div class="custom-target" style="width: 200px; height: 200px; background-color: red"></div>
              <moveable :target="target"></moveable>
            </div>
</div>
target = document.querySelector('.custom-target')

When I set position: relative , the moveable position did not match the element

is there any vue3 demo? thanks

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ChenWeihua123commented, Sep 13, 2021

image just like this and it’s amazing

<template>
  <v-moveable
    ref="moveableRef"
    v-bind="moveableState"
    @dragStart="onDragStart"
    @drag="onDrag"
    @resize="onResize"
    @resizeEnd="onResizeEnd"
    :container="container"
    :rootContainer="rootContainer"
  ></v-moveable>
</template>
<script lang="ts">
import { useStore } from '@/store';
import { computed, defineComponent, onMounted, PropType, reactive, ref } from 'vue';
import VMoveable, { MoveableProps, OnDrag, OnResize } from 'vue3-moveable';

export default defineComponent({
  components: { VMoveable },
  props: {
    selectedTargets: {
      type: Array as PropType<HTMLElement[]>,
      default: () => [],
    },
    zoom: {
      type: Number,
      default: 1,
    },
  },
  setup(props) {
    const store = useStore();
    const moveableRef = ref<VMoveable>();

    const zoom = computed(() => 1 / store.state.editor.scale);
    const select = computed(() => store.state.editor.select);
    const moduleTargets = computed(() => store.state.editor.moduleTargets);
    const selectedTargets = computed(() =>
      select.value
        .map(id => {
          return moduleTargets.value.get(id);
        })
        .filter(Boolean),
    );
    const target = ref<HTMLElement[]>([]);
    const moveableState = reactive<MoveableProps>({
      className: 'svt-moveable',
      draggable: true,
      resizable: true,
      // dragArea: true,
      origin: false,
      pinchable: true,
      zoom: zoom as unknown as number,
      throttleResize: 1,
      throttleDrag: 1,
      target: selectedTargets as unknown as HTMLElement[],
      // target: target as unknown as HTMLElement[],
    });
    const container = ref<HTMLElement | null>(document.querySelector('.panel-container'));
    const rootContainer = ref<HTMLElement | null>(document.body);

    setTimeout(() => {
      target.value = [document.querySelector('.custom-target') as HTMLElement];
    }, 2000);

    const onDragStart = () => {
      console.log('dragStart');
    }
    const onDrag = ({ transform, target, translate }: OnDrag) => {
      target.style.transform = transform;
    };
    const onResize = ({ target, width, height, drag }: OnResize) => {
      target.style.width = `${width}px`;
      target.style.height = `${height}px`;
      target.style.transform = drag.transform;
    };
    const onResizeEnd = () => {
      store.commit('editor/setRefresh');
    };

    onMounted(() => {
      console.log('moveableRef: ', moveableRef.value);
      console.log('moveableRef: ', moveableRef.value!.$_moveable.dragStart);
    });

    const getMoveable = () => {
      return moveableRef.value!.$_moveable;
    };

    return {
      moveableRef,
      onDrag,
      onResize,
      moveableState,
      container,
      rootContainer,
      zoom,
      onResizeEnd,
      getMoveable,
      onDragStart
    };
  },
});
</script>
<style lang="scss" scoped></style>

0reactions
ChenWeihua123commented, Oct 28, 2021

I see, I have time to try again

Read more comments on GitHub >

github_iconTop Results From Across the Web

Initial position · Issue #80 · daybrush/moveable - GitHub
So the question is how properly to set up an initial moveable position. By default, all elements are not selected. Vue template:
Read more >
Moveable Vertical Lines Not Saving Position Every time They ...
I am trying to create two points, (x,y) and (x2,y2) so that I can "save" both intersections of the vertical lines with the...
Read more >
Move Workers to Different Supervisor - Human Resources
Moving employees and/or positions to a different supervisor in Workday ... Workday will not allow any changes that may route to the wrong...
Read more >
How To Fix Unity Animation Position Issues - YouTube
A common mistake when using the Unity Animator is having GameObjects moving to incorrect positions.Here is a really quick way to fix that ......
Read more >
Moveable/draggable <div> - javascript - Stack Overflow
getElementById('dxy'); div.style.position = 'absolute'; div.style.top = e. ... Oh and you're also setting the event listener wrong. The way it is now, ...
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