Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Jan 25, 2018. It is now read-only.

Metal's drag and drop component.

License

NotificationsYou must be signed in to change notification settings

deprecate/metal-drag-drop

Repository files navigation

Build Status

Metal's drag and drop component.

Use

Simple use case

This instance ofDrag will allow any element with thebox class to bedragged, but only when clicking a child element that has thehandle class.

<divclass="box"><divclass="handle"tabindex="0"></div></div><divclass="box"><divclass="handle"tabindex="0"></div></div>
import{Drag}from'metal-drag-drop';newDrag({handles:'.handle',sources:'.box'});

drag

Locking axis

The drag elements can be locked to a specified axis, the following example wouldonly allow the elements to move along the y axis.

newDrag({axis:'y',sources:'.box'});

The same can be done for the x axis.

newDrag({axis:'x',sources:'.box'});

Constraining

By setting theconstrain element, the drag elements will not be allowed toleave the defined element's region.

newDrag({constrain:'#container',// Parent element of `.box` elementssources:'.box'});

Steps

Thesteps config property defines how much the drag elements will move by at atime.

newDrag({sources:'.box',steps:{x:50,y:150}});

steps

Cloning drag element

Rather than dragging the element itself, a clone can be created in it's place.

newDrag({dragPlaceholder:Drag.Placeholder.CLONE,sources:'.box'});

clone

Drag Drop

TheDragDrop class extends from theDrag class, but adds additional configproperties for defining target drop areas and behavior.

<divclass="box"></div><divclass="target"></div>
import{DragDrop}from'metal-drag-drop';constdragDrop=newDragDrop({sources:'.box',targets:'.target'});dragDrop.on(DragDrop.Events.END,function(data,event){event.preventDefault();console.log('Hit target:',data.target);// <div></div>});

Events

TheDrag class emits three events that can be listened to.

constdrag=newDrag({sources:'.box'});drag.on(Drag.Events.DRAG,function(event){// Logic});drag.on(Drag.Events.END,function(event){// Logic});drag.on(Drag.Events.START,function(event){// Logic});

TheDragDrop class adds two additional events related to drop targets.

constdragDrop=newDragDrop({sources:'.box',targets:'.target'});dragDrop.on(DragDrop.Events.TARGET_ENTER,function(event){// Logic});dragDrop.on(DragDrop.Events.TARGET_LEAVE,function(event){// Logic});

More examples

For more examples, check out thedemos.

Setup

  1. Install a recent release ofNodeJS if youdon't have it yet.

  2. Install local dependencies:

npm install
  1. Run the tests:
npm test
  1. Build the code:
npm run build
  1. Open the demo at demos/index.html on your browser.

Contributing

Check out thecontributing guidelines for more information.


[8]ページ先頭

©2009-2025 Movatter.jp