GithubHelp home page GithubHelp logo

mauricius / vue-draggable-resizable Goto Github PK

View Code? Open in Web Editor NEW
3.1K 44.0 542.0 3.44 MB

Vue3 Component for draggable and resizable elements.

Home Page: https://mauricius.github.io/vue-draggable-resizable/

License: MIT License

JavaScript 44.05% HTML 0.38% Vue 53.70% CSS 1.87%
draggable resizable component vuejs3

vue-draggable-resizable's Introduction

logo

VueDraggableResizable 3

Latest Version on NPM Software License npm

Vue Component for draggable and resizable elements.

If you are looking for the version 1 of the component, it is available on the v1 branch.

Table of Contents

Features

  • No dependencies
  • Use draggable, resizable or both
  • Define handles for resizing
  • Restrict size and movement to parent element
  • Snap element to custom grid
  • Restrict drag to vertical or horizontal axis
  • Maintain aspect ratio
  • Touch enabled
  • Use your own classes
  • Provide your own markup for handles

Live Playground

For examples of the component go to the live playground

Alternatively you can run the playground on your own computer:


Install and basic usage

$ npm install --save vue-draggable-resizable

Register the component globally

// main.js
import { createApp } from 'vue'
import VueDraggableResizable from 'vue-draggable-resizable'
import App from './App.vue'

createApp(App)
  .component("vue-draggable-resizable", VueDraggableResizable)
  .mount('#app')

You may now use the component in your markup

// App.vue
<template>
  <div style="height: 500px; width: 500px; border: 1px solid red; position: relative;">
    <vue-draggable-resizable :w="100" :h="100" :parent="true">
      <p>Hello! I'm a flexible component. You can drag me around and you can resize me.</p>
    </vue-draggable-resizable>
  </div>
</template>

The component itself does not include any CSS. You'll need to include it separately in your App.vue:

<style>
@import "vue-draggable-resizable/style.css";
</style>

Props

className

Type: String
Required: false
Default: vdr

Used to set the custom class of a draggable-resizable component.

<vue-draggable-resizable class-name="my-class">

classNameDraggable

Type: String
Required: false
Default: draggable

Used to set the custom class of a draggable-resizable component when draggable is enable.

<vue-draggable-resizable class-name-draggable="my-draggable-class">

classNameResizable

Type: String
Required: false
Default: resizable

Used to set the custom class of a draggable-resizable component when resizable is enable.

<vue-draggable-resizable class-name-resizable="my-resizable-class">

classNameDragging

Type: String
Required: false
Default: dragging

Used to set the custom class of a draggable-resizable component when is dragging.

<vue-draggable-resizable class-name-dragging="my-dragging-class">

classNameResizing

Type: String
Required: false
Default: resizing

Used to set the custom class of a draggable-resizable component when is resizing.

<vue-draggable-resizable class-name-resizing="my-resizing-class">

classNameActive

Type: String
Required: false
Default: active

Used to set the custom class of a draggable-resizable component when is active.

<vue-draggable-resizable class-name-active="my-active-class">

classNameHandle

Type: String
Required: false
Default: handle

Used to set the custom common class of each handle element. This way you can style each handle individually using the selector <your class>-<handle code>, where handle code identifies one of the handles provided by the handle prop.

So for example, this component:

<vue-draggable-resizable class-name-handle="my-handle-class"></vue-draggable-resizable>

renders the following:

<div ...>
  <div class="my-handle-class my-handle-class-tl"></div>
  <div class="my-handle-class my-handle-class-tm"></div>
  <div class="my-handle-class my-handle-class-tr"></div>
  [...]
</div>

scale

Type: Number|Array
Required: false
Default: 1

The scale prop controls the scale property when the CSS 3 scale transformation is applied to one of the parent elements. If not provided the default value is 1.

<vue-draggable-resizable :scale="0.5">

<vue-draggable-resizable :scale="[0.5, 0.4]">

disableUserSelect

Type: Boolean
Required: false
Default: true

By default, the component adds the style declaration 'user-select:none' to itself to prevent text selection during drag. You can disable this behaviour by setting this prop to false.

<vue-draggable-resizable :disable-user-select="false">

enableNativeDrag

Type: Boolean
Required: false
Default: false

By default, the browser's native drag and drop funcionality (usually used for images and some other elements) is disabled, as it may conflict with the one provided by the component. If you need, for whatever reason, to have this functionality back you can set this prop to true.

<vue-draggable-resizable :enable-native-drag="true">

active

Type: Boolean
Required: false
Default: false

Determines if the component should be active or not. The prop reacts to changes and also can be used with the syncmodifier to keep the state in sync with the parent. You can use along with the preventDeactivation prop in order to fully control the active behavior from outside the component.

<vue-draggable-resizable :active="true">

preventDeactivation

Type: Boolean
Required: false
Default: false

Determines if the component should be deactivated when the user clicks/taps outside it.

<vue-draggable-resizable :prevent-deactivation="true">

draggable

Type: Boolean
Required: false
Default: true

Defines it the component should be draggable or not.

<vue-draggable-resizable :draggable="false">

resizable

Type: Boolean
Required: false
Default: true

Defines it the component should be resizable or not.

<vue-draggable-resizable :resizable="false">

w

Type: Number|String
Required: false
Default: 200

Define the initial width of the element. It also supports auto, but when you start resizing the value will fallback to a number.

<vue-draggable-resizable :w="200">

h

Type: Number|String
Required: false
Default: 200

Define the initial height of the element. It also supports auto, but when you start resizing the value will fallback to a number.

<vue-draggable-resizable :h="200">

minWidth

Type: Number
Required: false
Default: 50

Define the minimal width of the element.

<vue-draggable-resizable :min-width="50">

minHeight

Type: Number
Required: false
Default: 50

Define the minimal height of the element.

<vue-draggable-resizable :min-height="50">

maxWidth

Type: Number
Required: false
Default: null

Define the maximum width of the element.

<vue-draggable-resizable :max-width="400">

maxHeight

Type: Number
Required: false
Default: null

Define the maximum height of the element.

<vue-draggable-resizable :max-height="50">

x

Type: Number
Required: false
Default: 0

Define the initial x position of the element.

<vue-draggable-resizable :x="0">

y

Type: Number
Required: false
Default: 0

Define the initial y position of the element.

<vue-draggable-resizable :y="0">

z

Type: Number|String
Required: false
Default: auto

Define the z-index of the element.

<vue-draggable-resizable :z="999">

handles

Type: Array
Required: false
Default: ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']

Define the array of handles to restrict the element resizing:

  • tl - Top left
  • tm - Top middle
  • tr - Top right
  • mr - Middle right
  • br - Bottom right
  • bm - Bottom middle
  • bl - Bottom left
  • ml - Middle left
<vue-draggable-resizable :handles="['tm','bm','ml','mr']">

axis

Type: String
Required: false
Default: both

Define the axis on which the element is draggable. Available values are x, y or both.

<vue-draggable-resizable axis="x">

grid

Type: Array
Required: false
Default: [1,1]

Define the grid on which the element is snapped.

<vue-draggable-resizable :grid="[1,1]">

parent

Type: Boolean
Required: false
Default: false

Restricts the movement and the dimensions of the component to the parent.

<vue-draggable-resizable :parent="true">

dragHandle

Type: String
Required: false

Defines the selector that should be used to drag the component.

<vue-draggable-resizable drag-handle=".drag">

dragCancel

Type: String
Required: false

Defines a selector that should be used to prevent drag initialization.

<vue-draggable-resizable drag-cancel=".drag">

lockAspectRatio

Type: Boolean
Required: false
Default: false

The lockAspectRatio property is used to lock aspect ratio. This property doesn't play well with grid, so make sure to use only one at a time.

<vue-draggable-resizable :lock-aspect-ratio="true">

onDragStart

Type: Function
Required: false
Default: null

Called when dragging starts (element is clicked or touched). If false is returned by any handler, the action will cancel. You can use this function to prevent bubbling of events.

<vue-draggable-resizable :onDragStart="onDragStartCallback">
function onDragStartCallback(ev){
   ...
   // return false; — for cancel
}

onDrag

Type: Function
Required: false
Default: null

Called before the element is dragged. The function receives the next values of x and y. If false is returned by any handler, the action will cancel.

<vue-draggable-resizable :onDrag="onDragCallback">
function onDragStartCallback(x, y){
   ...
   // return false; — for cancel
}

onResizeStart

Type: Function
Required: false
Default: null

Called when resizing starts (handle is clicked or touched). If false is returned by any handler, the action will cancel.

<vue-draggable-resizable :onResizeStart="onResizeStartCallback">
function onResizeStartCallback(handle, ev){
   ...
   // return false; — for cancel
}

onResize

Type: Function
Required: false
Default: null

Called before the element is resized. The function receives the handle and the next values of x, y, width and height. If false is returned by any handler, the action will cancel.

<vue-draggable-resizable :onResize="onResizeCallback">
function onResizeStartCallback(handle, x, y, width, height){
   ...
   // return false; — for cancel
}

Events

activated

Parameters: -

Called whenever the component gets clicked, in order to show handles.

<vue-draggable-resizable @activated="onActivated">

deactivated

Parameters: -

Called whenever the user clicks anywhere outside the component, in order to deactivate it.

<vue-draggable-resizable @deactivated="onDeactivated">

resizing

Parameters:

  • left the X position of the element
  • top the Y position of the element
  • width the width of the element
  • height the height of the element

Called whenever the component gets resized.

<vue-draggable-resizable @resizing="onResizing">

resizestop

Parameters:

  • left the X position of the element
  • top the Y position of the element
  • width the width of the element
  • height the height of the element

Called whenever the component stops getting resized.

<vue-draggable-resizable @resizestop="onResizestop">

dragging

Parameters:

  • left the X position of the element
  • top the Y position of the element

Called whenever the component gets dragged.

<vue-draggable-resizable @dragging="onDragging">

dragstop

Parameters:

  • left the X position of the element
  • top the Y position of the element

Called whenever the component stops getting dragged.

<vue-draggable-resizable @dragstop="onDragstop">

Styling

You can style the component using appropriate class names passed as props to the component. Moreover you can replace the default styles for the handles, provided in the source file vue-draggable-resizable.css, but you should take care to define position and size for them. The default classes for handles are handle and handle-tl, handle-br and so on.

The component also provides named slots for each handle, so you can use your markup inside each one.

Thanks

Thanks to @kirillmurashov for his work on vue-drag-resize component.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Any contribution to the code or any part of the documentation and any idea and/or suggestion are very welcome.

# serve with hot reload at localhost:8080
npm run dev

# distribution build
npm run build

# build the histoire docs
npm run story:build

# run tests
npm run test

# run histoire at localhost:6006
npm run story:dev

License

The MIT License (MIT). Please see License File for more information.

vue-draggable-resizable's People

Contributors

alireza0sfr avatar alxpez avatar cheerfulplum avatar dependabot[bot] avatar kybetter avatar lukeschafer avatar lzq920 avatar mauricius avatar mesqueeb avatar ojczeo avatar petrmixayloff avatar salemcode8 avatar selfagency avatar serhiy-shekhovtsov avatar tanghaojie avatar xiao-hongru avatar yanhuaguo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-draggable-resizable's Issues

BUG: still locks elements to the left/top despite :parent="false"

Hey there,
Great component! I noticed that even when you set the parent to false, the element is locked on the left side for resizing. This can be seen on the demo:

https://mauricius.github.io/vue-draggable-resizable/

Try to resize the element using the left or top handles under the "Basic component" title.

And if you drag it to the left, and then try to resize, it snaps back to be alongside the parent limit again.

Any way to get this fixed?

Fix for css transform?

First of all, this is a wonderful component and thank you so much for developing it. I have a small issue with it, when the parent element is modified by the css transform property the component does not move or resize according to the cursor position. Any idea how i could fix this? Thanks!

Is it possible to make a child element the "drag trigger"?

Hi there, thanks for writing such a great component!

I'm coding a game that simulates an OS, and I'm trying to create app windows (think of a Finder window, or a browser) that are draggable by the toolbar only (a child div). How could I go about setting a drag "trigger" instead of the whole window enabling the drag behaviour?

Some advices and issues

Hello, I am from China so excuse me for any mistakes since my not-so-good English.
I add a pseudo-class after Class active just like this:
.active:after { content:""; display: block; width: 100%; height: 100%; position: absolute; top: 0; left: 0; box-sizing: border-box; border: 1px dashed; },
I think it could be more clear when user is choosing an component and dragging it.
The maximize function should be optional and I don't like it most of time because its animation is too long.

The props of 'x' and 'y' have validator that must more than 0. That led to I can't drag it over the left or the top of its parent element even when I didn't set the 'parent' prop into true .Is there any reason to do this ? I don't think it is a good idea.

After all , this component is so great and I like it very much.

[feature request]allow auto for w,h,minw,minh when resizable is false

When sometimes I want to only drag something, the default value of w,h,minw,minh affect me a lot,
for that I need to calculate these where it's almost impossible.
So could these values be a string "auto" which means don't touch original value if not resizable, or calculate these values automatically when dom is ready?

input inside vue-draggable-resizable component

In version 1.2.4, i was could insert input inside the vue-draggable-resizable component, and still have a focus on the input, and the ability to move it. Since version 1.2.5 I can't do this anymore. I'm quite satisfied with version 1.2.4, but there is console.log in the watcher of position.

script-code in documentation

Currently the documentation only shows the html but not the <script> [....] </script> part of the apps. However, it would be nice to be able to see how the event handlers are called, etc. Do you think it should be included in the documentation? If so, I could do that and send a pr, if you like

Thoughts on children VDRs inside parent VDR (handling recursion)

I stumbled upon the case-scenario in which a VDR may have other VDRs as children. Having the prop :parent=true maintains the children within the parent boundaries (as expected GOOD!), but the activation mechanism (meaning whether or not a VDR is active) occurs in all children VDRs (included the parent VDR). In this case, when trying to drag a child, the parent would move as well (once the child has reached the parent boundaries).

Probably not the best explanation (hard to do it in words... I'll try to post a visual example), but I hope my point goes through. I will be looking into vdr code to find possible solutions. However, this feature might not be within your development plans.

Any thoughts on this? Cheers!

Is there a reason why the elements don't react to changes of their props?

If the props of an vue-draggable-resizable change (e.g. x, h) change after the initial rendering of the object, the object is not rerendered. Hence, the changes are ignored. Probably this is due to the fact, that these props are only used in the created and mounted functions? Is there a special reason for that? I would like to be able to control the position of an element reactively based on the state of my app.

Is this a bug?

Reloading page using shortcut key ('command + r') when the cursor over the draggable element(don't move cursor) then move the draggable element you can see bellow gif:

qweqw

sorry, poor English

That seems handle the first move on the draggable element the diffX/Y equals the fisrt page.x

cannot change the 'width' ,'height' ,'top' and 'left' when the props change.

watcher:
x (param) { this.x = param.position.left },
w (param) { this.width = param.width },
h (param) { this.height = param.height }

here are all codes:
<template>
   <div class="bz-ed-unit">
      <vue-draggable-resizable
      :w="param.width" :h="param.height" 
      :x="param.position.left" :y="param.position.top" 
      :active="currentUnit.id === param.id ? true : false"
      @dragging="onDrag" @dragstop="onDragstop" 
      @resizing="onResize" @resizestop="onResizstop"

      @deactivated="onDeactivated" @activated="onActivated"
      :parent="false" :class="[param.background.type === 'LINES' ?  param.background.data + ' lines-one' : '']"
      :style="{ backgroundColor:  param.background.type === 'COLOR' ? param.background.data : '', 
        backgroundImage: param.background.type === 'IMAGE' || param.background.type === 'VIDEO' ? 'URL(' + param.background.data + ')' : '' }">
      <span class="bz-param-text">X: {{ x }} &nbsp; Y: {{ y }} &nbsp; W: {{ width }} &nbsp; H: {{ height }}</span>
      <ed-text :param="param"></ed-text>
    </vue-draggable-resizable>
  </div>
</template>

<script>
import EdText from './text'
import VueDraggableResizable from 'vue-draggable-resizable'
import { mapGetters, mapActions } from 'vuex'
export default {
  name: 'ed-unit',
  props: [ 'param' ],
  data () {
    return {
      width: 0,
      height: 0,
      x: 0,
      y: 0
    }
  },
  computed: {
    ...mapGetters([
      'layout', 'currentUnit'
    ])
  },
  watch: {
    param (param) {
      this.width = param.width
      this.height = param.height
      this.x = param.position.left
      this.y = param.position.top
    }
  },
  methods: {
    ...mapActions([ 'setActive', 'removeActive', 'updateUnit' ]),
    onResize: function (x, y, width, height) {
      this.x = x
      this.y = y
      this.width = width
      this.height = height
    },
    onDrag: function (x, y) {
      this.x = x
      this.y = y
    },
    update () {
      this.updateUnit({
        width: this.width,
        height: this.height,
        position: { top: this.y, left: this.x }
      })
    },
    onDragstop (v) {
      this.update()
    },
    onResizstop () {
      this.update()
    },
    onDeactivated () {
      // this.removeActive()
    },
    onActivated () {
      this.setActive(this.param)
    }
  },
  components: { VueDraggableResizable, EdText }
}
</script>

<style scoped>

.bz-ed-unit{
  position: relative;
}

.bz-param-text{
  display: none;
}

.vdr.active .bz-param-text{
  display: inline-block;
  position: absolute;
  margin-top: -30px;
  width: 250px;
  padding: 5px;
  background-color: white;
}

</style>

please...

[FEATURE] Prevent overlapping of elements

Hello,

I want to build an event calender and was wondering if there is any way by default to disable overlapping of two elements?
So eg. in a calender if you have 2 events they shouldn't overlap visually. (because you can't be at two events at the same time)

Cheers.

How to manually update X and Y

Is any way to manually update props: X and Y?
My code didn't work ( only prop text has been updated ):

<template>
  <div id="app">
    <div style="height: 300px; border: 1px solid blue; margin: 0">
      <template v-for="element in elements">
        <vue-draggable-resizable :parent="true" :resizable="true" :x.sync="element.x" :y.sync="element.y" style="border: 1px solid">
          <p :style="{ color: element.color }">{{ element.text }}<button @click="reset(element)">reset</button></p>
        </vue-draggable-resizable>
      </template>
    </div>
  </div>
</template>

<script>
import VueDraggableResizable from './components/vue-draggable-resizable'

export default {
  name: 'app',
  components: {
    'vue-draggable-resizable': VueDraggableResizable
  },
  data: function () {
    return {
      elements: [
        {
          text: 'Component 1',
          x: 0,
          y: 0,
          color: 'red'
        },
        {
          text: 'Component 3',
          x: 0,
          y: 200,
          color: 'blue'
        }
      ]
    }
  },
  methods: {
    reset: function (element) {
      element.x = 0
      element.y = 0
      element.text = 'RESET'
    }
  }
}
</script>

<style>
  .active {
    border: 1px dashed black;
  }
</style>

Maintain aspect ratio on resizing?

Are there any plans to add this functionality anytime soon? Possibly as a prop boolean value or another common experience is when users hold the shift key on resize to maintain the ratio.

size auto increase when mouse double click

while I double click the resize component,the size of it will automatic increase util occupy the whole parent container.
demo page, Component costrained on x axis example,

Cannot make it work

After installing the package I'm getting this error

 ERROR  Failed to compile with 2 errors                                                                                                 11:03:17 AM

This dependency was not found:

* vue-draggable-resizable in ./src/main.js, ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Home.vue

To install it, you can run: npm install --save vue-draggable-resizable

draggable-dependency

The package name is present in package.json ("vue-draggable-resizable": "1.0.0",) as well as stored under node_modules

Vue version is 2.3.3
Node evrsion v6.1.0

It seems there is no dist folder:
no_dist

Is it possible to fix the resizing logic ?

@mauricius Currently, looking at the code when resizing using the grid, the component's width will be changed by doing a

grid.width * deltaW / grid.height * deltaH

the problem with this approach is that it changes the inital width with is an unwanted behaviour.
Shouldn't it just add to the inital width/height like so

this.width + (grid.width * deltaW) /this.width + grid.height * deltaH

You can please refer to jquery-ui resizable for any more clarification.

This is a screenshot of the problem that I came across
Dynamic Tile Builder
The tile in the screenshot needs to be contained inside the grid cells but the problem is that the tile width gets changed even without resizing.

How to distinguish between multiple components in event handler

Currently event handlers like resizestop only receive dimension values like [x, y, w, h], which is not enough to tell which component just got resized.

A suggested solution is to allow an addition prop as unique ID.

Even better, accept a component configuration object, which shall include all necessary configurations, and in case of move or resize, all dimensional values could be directly altered directly in the configuration

Mouse events are prevented by draggable-resizable component

Hi, I'm trying this component in my app. It's very nice 🙂

One thing I encontered with this component is that it seems to capture all mousedown/move/up events and prevent other event listeners and native behaviors.
In my app, there are text input forms in draggable/resizable elements. And I also want to handle other drag events when the users drag out of draggable elements.

Here is the example for describing the above problem.
https://jsfiddle.net/kbhce3ht/

Is there any chance to satisfy such scenario somehow?

Using in a project based on browserify

Hi,
I would like to use vue-draggable-resizable in a project set up using the vue cli with the browserify option. When trying to import VueDraggableResizable I get the error message:

Error: Cannot find module '!!../../node_modules/css-loader/index.js!../../node_modules/vue-loader/lib/style-compiler/index.js?{"id":"data-v-1e95fd0f","scoped":true,"hasInlineConfig":false}!../../node_modules/vue-loader/lib/selector.js?type=styles&index=0!./vue-draggable-resizable.vue' from 'C:\Users\lmrin\tutorials\vue-form2\node_modules\vue-draggable-resizable\dist'

I already tried to install css-loader. However this didn't result in a working import. Does anybody know how to convert this package to be usable in browserify projects? And could you maybe include browserify builds in future versions?

Cheers
Lars

Bug: in case of using v-show, when start resizing, element size changes to 50x50px

Hi. First of all thank you for the component!

Regarding the problem:
The size changes to default minw and minh which is 50px. In case of v-if everything works ok, but I need v-show, because in background my element does some stuff.

Example: https://jsfiddle.net/t82k21gx/1/

<template>
  <button @click="showShow = !showShow">Switch show</button>

  <vue-draggable-resizable :w="250" :h="250" :x="100" :y="100" v-show="showShow">
    <p>You can drag me around and resize me as you wish.</p>
  </vue-draggable-resizable>
</template>

<script>
  export default {
    data () {
      return {
        showShow: false
      }
    }
  }
</script>

I would appreciate any workaround.

how do i use it outside of a build system

Currently i am having an app outside of the .vue component mechanism. Is there a way where i can use this component in such cases.

I have added <script src="//unpkg.com/vue-resource"></script> and then Vue.component('vue-draggable-resizable', VueDraggableResizable) to try it out. But doesn't seem to work.

any pointers ?

Is it possible to have some sort of overlap detection ?

I would like to know if there is some sort of way to detect element overlapping ?
I'm building a dynamic tile grid ui with jquery-ui-draggable/resizable, problem is that it's too much code to maintain and it's ui reliant in most cases using this approach

$('.tile.ui-resizable:not(.tile.ui-resizing)').each(function ( {
    // logic to check the current tile against all the existing tiles
}))

And yes in this instance I really need collision detection.

Draggables "pile down" if constructed using v-for

When I want to generate multiple draggables within one parent div using the v-for directive, the domain in which they can move in the y-direction piles up from the space in the y-direction, their predecessors are using.

So for example if the first element constructed using v-for has a size of (100, 100) and the second element is supposed to appear at (0,0), it appears at (0, 100) of the parent component but thinks, it is at (0, 0). As a consequence it can be moved down to y=(600-own height), even if the domain is only supposed to have a size of 500. Interestingly, this piling only occurs in the y-direction but not in the x-direction. I don't know whether the issue becomes clear in my description, so here is some example code.

<template>
<div id="app" class="container">
  <div style="height: 500px; width: 500px; border: 1px solid red; position: relative;">
    <template v-for="element in elements">
      <vue-draggable-resizable :parent="true" :resizable="true" :x="element.x" :y="element.y" @dragstop="(x,y) => updateElementPosition(element, x, y)" style="border: 1px solid">
        <p>{{ element.text }}</p>
        <p>x-position: {{ element.x }} y-position: {{ element.y }}</p>
      </vue-draggable-resizable>
    </template>
  </div>
</div>
</template>

<script>
import VueDraggableResizable from 'vue-draggable-resizable'

export default {
  name: 'app',
  components: {
    VueDraggableResizable
  },
  data () {
    return {
      elements: [
        {
          text: 'I can be moved around freely within the parent',
          x: 0,
          y: 0
        },
        {
          text: 'My initial position is set to 0,0 but I appear below the previous element at 0, 200 and can be moved further down than the border of my parent',
          x: 0,
          y: 0
        },
        {
          text: 'I appear below the lower end of my predecessor. If the size of one of them is changed, I move accordingly without changing my coordinates',
          x: 0,
          y: 0
        }
      ]
    }
  },
  methods: {
    updateElementPosition (element, x, y) {
      element.x = x
      element.y = y
    }
  }
}
</script>

I'm using vue-draggable-resizable 1.2.2 and Vue 2.3.4

zIndex increments automatically on elmDown calls

I've noticed that the zIndex keeps on incrementing once the element recovers focus. This is explicitly covered on the elmDown method, where you check if the element !active and if so, change it to active and increase zIndex.

This in turns makes the zIndex increment without limits, and when you have more than one element on screen clicking between them results on a racing game.

My inquiry has two parts, the first one being to remove the auto-increase behaviour (unless this is something necessary, for something I'm not aware of). The second one is more of a feature request similar to #14, in which a :zIndex prop is made accesible.

Does this conflict with any internal working of the component?

opacity set to 0.6 when single click

when single click the pane( not drag it), it turns to opacity=0.6 and then opacity=1. this isn't what I want. I think the opacity should be 0.6 only when it's dragging.

dragHandle and dragCancel errors in docs

Just reporting some small errors. dragHandle needs to be written like this to work:

:drag-handle="'.drag'"  // note extra ''

And dragCancel has :drag-handle in the example instead of :drag-cancel

Cheers,

In addition to the elements can not get the focus?

After the introduction, I guess event binding in the document, so lead to elements such as form can not get the focus?

I expect them to not affect each other. How to solve? Can help me?

eg: 
<div id="app1">
    <div class="container">
        <input type="text" />
        <div style="height: 300px; border: 1px solid blue; margin: 1em;">
            <vue-draggable-resizable style="border: 1px solid black;"></vue-draggable-resizable>
        </div>
    </div>
</div>

Dragging/Resizing element adds width

This is an odd behaviour, I've set the :w="128" :h="128" but oddly I found that after dragging/resizing an element, the width/height of the element becomes 132/132 respectivly.

Is it a normal behavour or what ? and if it is, how can I prevent such behaviour.

A good library that provides robust ui handling.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.