npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

v-drag

v3.0.9

Published

The simplest way to integrate drag on Vue.js

Downloads

58,109

Readme

v-drag

The simplest way to integrate drag on Vue.js.

Draggable elements are a common UX pattern, specially on touch screens. But as a developer, you might know how challenging it is to apply it with JavaScript. So to simplify things, v-drag was written. Its aim is to quickly integrate and customize draggable elements on projects using Vue.js.

Build status npm package Version License

Table of contents

  1. Installation
  2. Usage
  3. Options
    1. Axis
    2. Snap
    3. Handle
  4. Vue events
  5. Global configuration
    1. Event classes
    2. Remove transitions

Installation

npm install v-drag --save

v-drag’s source code is also available uncompressed and minified.

Usage

Import v-drag into any file you are planning to use it:

import drag from "v-drag"
const drag = require("v-drag");

Then call the v-drag plugin:

Vue.use(drag, {
  // global configuration
});

No extra setup is necessary at this point. Add the v-drag attribute to any element to make it draggable:

<div v-drag>Drag me!</div>

Options

The default behavior for any element with the v-drag attribute is to be draggable in any direction and without a handle. However, this can be changed using an object or its equivalent shortcuts:

<div v-drag="{ axis: 'x', handle: '#someElement' }">
  <div id="someElement">Handle</div>
</div>

Both the object and the values can be declared inline, as in the example above, or using the data object, computed properties, methods, props,…

Axis

Constrains the element to move only in one direction: horizontal or vertical.

Values

  • all: all directions default
  • x: horizontal movement
  • y: vertical movement

Shortcut

<div v-drag:x>Horizontal</div>

Snap

When dragging, the element will snap to the specified grid. You can use either a number or a string with units.

<div v-drag="{snap: 100}">Drag me in 100px increments</div>

Using an array, different values can be declared for each axis:

<div vdrag="{snap: [10, 50]}">
  Horizontal: 10px
  Vertical: 50px
</div>

Handle

Informs that the element can only be dragged using another element, known as handle. It’s not necessary for the handle to be located inside the draggable element, and each element can have more than one handle.

Values

Handle’s name must be a selector (the same used to refer to the element in CSS) or a Ref.

Shortcut

<div v-drag="'.someElement'">Don’t drag me</div>
<div class="someElement">Drag me</div>

Ref

To define handles using Refs, you must first set its value in data and replace it after the component is mounted:

<template>
  <div v-drag="{handle}">
    Drag me using handle
    <div ref="drag-handle">Handle</div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      handle: undefined,
    }
  },

  mounted() {
    this.$data.handle = this.$refs.dragHandle
  }
};

</script>

Vue events

These events are emitted when the user makes the corresponding action.

<div v-drag @v-drag-end="someFunction()">
  Event on end
</div>

| Event | Description | |-------------------------|----------------------------------------------------------------------------| | @v-drag-setup | The component has completed the initial setup | | @v-drag-start | The user has pressed the draggable element and its mouse or finger is down | | @v-drag-moving | The user is moving the mouse or finger | | @v-drag-end | The user has released its mouse or finger | | @v-drag-update | Changes in the configuration of the draggable options | | @v-drag-axis-update | The axis has been updated | | @v-drag-handle-update | The handle has been updated |

Global configuration

Event classes

v-drag uses CSS classes to add basic styling to the draggable elements. You can override one or multiple of the default classes when the plugin is called:

Vue.use(drag, {
  eventClass: {
    down: "is-pressed",
    move: "is-moving"
  }
});

This are the default classes with its values:

| Name | Default value | Description | |-------------|--------------------|---------------------------------------------- | | initial | drag-draggable | The element is draggable | | hasHandle | drag-uses-handle | The element uses a handle | | handle | drag-handle | The element is the handle of another element | | down | drag-down | The user has pressed the element | | move | drag-move | The user has started to drag the element |

Remove transitions

By default, v-drag removes all transition animations to keep the dragging as smooth as possible. However, if you want to enable them, you can:

Vue.use(drag, {
  removeTransition: false // default: `true`
});