dnd.js

Installation method

  • Methods a
npm install dnd.js --saveCopy the code

  • Way 2
Download dist/dnd.js from your project and insert it into your project with the script tag, which can be accessed through window.dndCopy the code

<script type="text/javascript" src="dist/dnd.js"></script>Copy the code

Parameters that

  • create
new Drag(element, options)
new Drop(element, options)Copy the code

parameter If required type instructions
element is String or htmlElementObject You can pass in a class name or an ID name or a DOM node
options is Object The parameters and callback functions are described below
  • The options (Drag)

Such as:

  let element = '.drag-container'
  let options = {
    data: 'Drag the parameter that you want to pass to the Drop object'.onDragStart: function (params) {
      console.log('Listen until the drag starts')},onDragEnd: function (params) {
      console.log('Listen until the drag ends')}}new Drag(element, options)Copy the code

Options property description:
attribute If required type instructions Description of callback function parameters
name no String Defines the name of the current Drop object
onDragStart no Function Called when a drag starts See instructions below
onDragEnter no Function Called when you drag to enter See instructions below
onDragOver no Function Called when the dragged element moves above itself. This function is called continuously See instructions below
onDragLeave no Function Called when dragging away See instructions below
onDrop is Function Called when the dragged element is dropped over itself See instructions below
onDragEnd no Function Called when the drag ends See instructions below
The methods object in the callback function is described as follows:

Provides methods to call callback functions

  • ShowStateicon: displays the status icon. Example: showStateicon(‘add’)

Ss2.bdstatic.com/lfoZeXSm1A5…

  • HideStateicon: Hides the status icon

  • RemoveDragedNode: removeDragedNode: removeDragedNode(‘fade’) : removeDragedNode(‘fade’)

  • GetStateIconNode: Gets the dom node of the state icon that moves with the mouse

  • DestroyDrop: Destroys the current Drop object

The method name The sample Parameters that describe
showStateicon params.methods.showStateicon(‘add’) Parameter type: String, built-in three common ICONS: add (‘add’), error (‘error’), Delete (‘delete’), reject (reject), pass the corresponding name, you can also customize the icon, directly pass the full address of the picture Display status icon. After calling, a small icon will appear next to the mouse to move with the mouse. To hide it, just call hideStateicon function
hideStateicon params.methods.hideStateicon() There is no parameter Hide status ICONS that move with the mouse (ICONS are not displayed by default if showStateicon is not called)
removeDragedNode params.methods.removeDragedNode(animationName, time) AnimationName (animation type), parameter type :String, optional: fade/blost/back, time(animation time, in milliseconds), parameter type: Number, optional Remove the dragged element that moves with the mouse, and if there is no parameter, it will disappear directly. If there is a parameter, it means that the vanishing animation is performed and then disappears. Currently, there are three kinds of animations supported, namely, fade, Blost and Rebound. removeDragedNode(‘blost’, 300)
getStateIconNode params.methods.getStateIconNode() There is no parameter Returns the status icon DOM node that moves with the mouse
destroyDrop params.methods.destroyDrop({name}) Parameter type: String, Drag the name of the object The Drag object cannot be received after the Drop object is destroyed