LoginSignup
3
6

More than 5 years have passed since last update.

touchデバイスでもドラッグ&ドロップでsortableしたい

Posted at

npmインストール

npm i sortablejs

使い方

<ul id="items">
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
</ul>
var el = document.getElementById('items');
var sortable = Sortable.create(el);

ul/liじゃなくても親タグの下に子タグが並んでるようなdom構成なら、どこにでも使えます。

子要素全体を掴ませたくない場合は子要素の一部をdraggableにできます。
いろんなイベントが定義されていて動作のカスタマイズが出来ます。

Sortable.create(this.$main[0], {
  handle: '.handleCol',
  onStart: () => this._onStartDragOnSort(),
  onEnd: () => this._onEndDragOnSort(),
  onUpdate: e => this._onUpdate()
});

参考

RubaXa/Sortable
https://github.com/rubaxa/Sortable
demoページ
http://rubaxa.github.io/Sortable/

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6