New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@redbuck/sorter

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@redbuck/sorter

drag to sort element

latest
Source
npmnpm
Version
0.0.9
Version published
Weekly downloads
1
-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

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

DEMO

DEMO

安装

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

引入

插件打包格式为UMD

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

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

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

使用

  • 一般用法
<ul class="free" id="free">
  <li class="item item-1">item-1</li>
  <li class="item item-2">item-2</li>
  <li class="item item-3">item-3</li>
  <li class="item item-4">item-4</li>
  <li class="item item-5">item-5</li>
  <li class="item item-6">item-6</li>
  <li class="item item-7">item-7</li>
  <li class="item item-8">item-8</li>
</ul>
new Sorter(document.getElementById('free'))
  • 结合MVVM框架 以VUE为例
  mounted() {
	this.dragger = new Sorter(this.$refs.list, {
	  change: false,
	})
	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];
	},

预览

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

Keywords

drag

FAQs

Package last updated on 07 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts