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

lite-move

v0.0.5

Published

a directive for moveable element which being able to run on vue2 and vue3. and it does not depense on position but use transform.

Downloads

7

Readme

lite-move

一个使用transform实现dom元素拖动的vue指令,对外部环境要求更少,不再依赖position,任何元素都可以高效拖动!

另外,兼容原生js、vue2、vue3!!

安装

npm i lite-move --save

特点

  • 使用transform来实现元素的移动,性能更好
  • 不依赖position,不会修改top和left等定位属性,更健壮,任何元素都可以拖动
  • 可在原生js、vue2、vue3中使用

使用

如果需要将指令注册为全局指令,可通过安装插件来自动注册,该插件自动识别vue版本,会根据环境自动安装对应版本的指令。

import { moveDirectivePlugin } from 'lite-move'
// 安装插件(在vue2中app是Vue构造函数,而在vue3中app是createApp返回的对象)
app.use(moveDirectivePlugin).mount('#app')

在vue3、vue2、原生js中使用示例如下:

vue3

注册为全局指令

安装moveDirectivePlugin插件,会在全局注册一个v-move的指令,添加了v-move指令的元素可自由拖动

// main.js
import { createApp } from 'vue'
import App from './App.vue'
import { moveDirectivePlugin } from 'lite-move'

const app = createApp(App);
// 根据环境自动注册为全局指令v-move
app.use(moveDirectivePlugin).mount('#app')

/*
使用:<div v-move> </div>
*/

注册为局部指令

<template>
  <div ref="moveEle" v-move>
    <span>移动</span>
  </div>
</template>

<script setup lang='ts'>
import { moveDirective } from 'lite-move';
// 注册局部指令
const vMove = moveDirective;
</script>

<script lang="ts">

/* 选项模式
import { moveDirective } from 'lite-move';
export default {
  directives: {
    // 在模板中启用 v-move2
    move2: moveDirective
  }
}
 */
</script>

<style scoped>
div {
  width: 100px;
  height: 100px;
  border: brown 3px solid;
  background-color: green;
  cursor: move;
}
</style>

vue2

注册为全局指令

安装moveDirectivePlugin插件,会在全局安装一个v-move的指令,添加了v-move指令的元素可自由拖动

// main.js
import Vue from 'vue'
import App from './App.vue'

import {moveDirectivePlugin} from 'lite-move'
Vue.use(moveDirectivePlugin) // 注册全局指令v-move

new Vue({
  render: (h) => h(App)
}).$mount('#app')

/*
使用:<div v-move> </div>
*/

注册为局部指令

<template>
    <div v-move>
        <span>{{ title }}</span>
    </div>
</template>

<script>
import { moveDirectiveFor2 } from 'lite-move';
export default {
    data() {
        return {
            title: '移动',
        }
    },
    directives: {
        // 注册局部指令
        move: moveDirectiveFor2
    }
}
</script>
  
<style scoped>
div {
    width: 100px;
    height: 100px;
    border: brown 3px solid;
    background-color: green;
    cursor: move;
}
</style>

原生js

在原生环境中,将拖动函数:liteMove.toMove(),注册为需要拖动dom元素的mousedown事件处理函数,即可让元素实现拖动。

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>liteMove</title>
    <style>
        #move {
            width: 100px;
            height: 100px;
            background: #69c810;
            cursor: move;
        }
    </style>
</head>

<body>
    <div id="move">
        any dom moveable
    </div>
</body>
<script src="./dist/lite-move.umd.js"></script>
<script>
    // liteMove.toMove() 返回监听mousedown事件的处理函数
    const movableAction = liteMove.toMove();
    document.querySelector('#move').addEventListener('mousedown', movableAction);
</script>

</html>