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

@redbuck/draggerjs

v1.1.0

Published

library to drag Elements

Downloads

3

Readme

这是一个用于拖拽排序的包.

DEMO

DEMO

安装

npm i @redbuck/draggerjs或者 yarn add @redbuck/draggerjs

引入

插件打包格式为UMD

因此既可以使用<script>标签引入,然后直接使用window.Dragger

也可以通过importrequire的方式引入.

注意,插件使用了部分ES6API,如需兼容需要添加polyfill或者配置babel-runtime等.

使用

  1. 一般用法
 <div id="wrap">
    <div class="item">item - 1</div>
    <div class="item">item - 2</div>
    <div class="item">item - 3</div>
    <div class="item">item - 4</div>
 </div>
new Dragger(document.getElementById('wrap'))
  1. 结合MVVM框架 以VUE为例
  mounted() {
	this.dragger = new Dragger(this.$refs.list, {
	  // 关闭自动换位
	  change: false,
	})
	// 拖拽结束时,实例对外抛出drag-over事件.
	// 携带对象{source: number, target: number}
	// 可以知道是哪两个元素需要交换位置
	this.dragger.on('drag-over', pos => {
	  this.changeItem(pos);
	  // 在合适的时机刷新实例
	  setTimeout(() => {
		this.dragger.freshThreshold();
	  }, 20)
	})
  }

知道了需要交换位置的元素,开发者可以自行操作数据,示例如下

	changeItem({source, target}) {
	  let list = this.list;
	  let temp = list.splice(source, 1);
	  let start = list.splice(0, target);
	  // do something
	  this.list = [...start, ...temp, ...list];
	},

参数

参数 | 类型 | 默认值 --:|--:|--: el | Element | undefined option | Object | {dir: 'y', change: true}

dir可选[x, y],决定排序方向 change表示拖拽结束是否自动换位

预览

  1. 运行git clone https://github.com/xty1992a/draggerjs.git
  2. 进入项目根目录,运行npm iyarn
  3. 运行npm run dev
  4. 浏览器查看localhost:8080