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

vue-device-drag

v0.1.20

Published

基于vue2、3整合mouse、touch拖拽

Downloads

22

Readme

vue-device-drag

简介

基于Vue2、3,整合了mouse、touch而成的拖拽指令,便于一套代码同时应用于pc端和设备端

使用方法

npm install vue-device-drag

vue2:

import DeviceDrag from "vue-device-drag";

Vue.use(DeviceDrag)

vue3:

import { createApp } from 'vue'
import App from './App.vue'
import { vue3 as DeviceDrag } from "vue-device-drag";

createApp(App).use(DeviceDrag).mount("#app");

作用于拖拽元素的指令

| 指令名 | 说明 | 指令的绑定值类型 | |:-----------------------:|:------------------------------------------------:|:----------------------------:| | device-drag | 启用拖拽功能,需要拖拽的元素必须有 | × | | device-drag-delay | 延迟拖拽的时间(ms),注意:mouse-delay、touch-delay指令优先级大于该指令 | Number | | device-drag-mouse-delay | 当拖拽的为鼠标事件的时候,延迟拖拽的时间(ms) | Number | | device-drag-touch-delay | 当拖拽的为触摸事件的时候,延迟拖拽的时间(ms) | Number | | device-drag-disable | 动态控制是否允许拖动 | Boolean | | device-drag-data | 指定该元素触发拖拽相关指令时,绑定的数据 | String / Number / Boolean / Object | | device-drag-start | 指定元素触发拖拽开始指令时,调用的方法 | Function | | device-drag-end | 指定元素触发拖拽结束指令时,调用的方法 | Function |

作用于目标元素的指令

| 指令名 | 说明 | 指令的绑定值类型 | |:-------------------:|:-----------------------:|:---:| | device-drag | 启用拖拽功能,需要拖拽的元素必须有 | × | | device-drag-disable | 动态控制是否允许拖动 | Boolean | | device-drag-data | 指定该元素触发拖拽相关指令时,绑定的数据 | String / Number / Boolean / Object | | device-drag-enter | 指定拖拽元素进入目标元素时,调用的方法 | Function | | device-drag-over | 指定拖拽元素在目标元素上移动时,调用的方法 | Function | | device-drag-leave | 指定拖拽元素离开目标元素时,调用的方法 | Function | | device-drop | 指定拖拽元素在目标元素上结束拖拽时,调用的方法 | Function |

事件类指令调用绑定的方法时,传入的参数中带有以下参数

| 参数名 | 说明 | 数据类型 | |:-------------------:|:----------------------------:|:------:| | eventName | 若使用指令时,有传入指令参数,则值为指令参数,否则为空 | String | | clientX | 事件触发时,鼠标的位置 | Number | | clientY | 事件触发时,鼠标的位置 | Number | | pointEl | 事件触发时,鼠标所在的元素(不代表一定是事件触发的元素) | Element | | dragEl | 拖拽元素 | Element | | data | 拖拽元素使用device-drag-data绑定的数据 | String / Number / Boolean / Object | | target | 目标元素 | Element | | targetData | 目标元素使用device-drag-data绑定的数据 | String / Number / Boolean / Object |

指令参数

当指令device-drag使用时带有参数,如:

v-device-drag:test

则只有带有相同参数test的事件指令才会被触发,如:

v-device-drag-start:test="doSomething"

v-device-drag-end:test="doSomething"

v-device-drag-enter:test="doSomething"

v-device-drag-over:test="doSomething"

v-device-drag-leave:test="doSomething"

v-device-drop:test="doSomething"

事件指令可通过增加修饰符stop来阻止事件的冒泡传递,如:

v-device-drag-over:test.stop="doSomething"

判断是否正在拖拽过程中

if (this.$deviceDrag) {
    // 拖拽过程中
}

使用示例

<template>
  <div id="app">
    <div
        v-device-drag-data="{ groupId: 1 }"
        v-device-drag-enter="dragOver"
        v-device-drag-over="dragOver"
        v-device-drag-leave="dragEnd"
        v-device-drop="drop"
        :class="['group', 'group1', { 'is-over': overGroupId === 1 }]">
      <img
          v-device-drag
          v-device-drag-end="dragEnd"
          alt="Vue logo"
          src="./assets/logo.png">
    </div>
    <div
        v-device-drag-data="{ groupId: 2 }"
        v-device-drag-enter="dragOver"
        v-device-drag-over="dragOver"
        v-device-drag-leave="dragEnd"
        v-device-drop="drop"
        :class="['group', 'group2', { 'is-over': overGroupId === 2 }]"
    ></div>
  </div>
</template>

<script>

export default {
  name: 'App',
  data() {
    return {
      overGroupId: null,
      group1: [],
      group2: []
    }
  },
  methods: {
    dragOver(event) {
      this.overGroupId = event.targetData.groupId
    },
    dragEnd() {
      this.overGroupId = null
    },
    drop(event) {
      event.target.append(event.dragEl)
    }
  }
}
</script>

<style>
#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.group {
  width: 300px;
  height: 300px;
  border: 1px solid #cccccc;
  margin: 10px auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  transition: background-color 0.2s linear;
}

.group.is-over {
  background-color: aliceblue;
}
</style>