Git Product home page Git Product logo

sorter's Introduction

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

DEMO

DEMO

安装

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

引入

插件打包格式为UMD

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

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

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

使用

  1. 一般用法
<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'))
  1. 结合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];
	},

预览

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

sorter's People

Contributors

xty1992a avatar yangyongan avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.