1.0.18 • Published 2 years ago

drageverywhere v1.0.18

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

drag

这个库可以让你从源区域拖动到目标区域,并提供等比例的换算

安装方式

npm i drageverywhere
or 
yarn add drageverywhere

例子运行

你可以fork这个仓库,或者下载源代码地址

yarn install --frozen-lockfile
or 
npm ci
npm run start_server
npm run serve

分别打开

http://localhost:8080/source

http://localhost:8080/listener

在source页面进行操作,listener页面数据监听页面,即可看到效果

usage 使用方法

new Drag({
          sourceBox: '#home-box',
          dragBox: '#move-box',
          referBox: '#move-box',
          dragTargetClassName: 'c-item',
          imgs: 'img地址或require',
          dragNumber: 4,
          aspectRatio: '16:9',
          dragMaxWidth: 600,
        })

参数说明

参数说明类型必要的默认值
sourceBox需要被拖动的父盒子(源区域)IDString*-
dragBox被拖入的盒子(目标区域)IDString*-
dragTargetClassName(目标元素)目标拖动元素类名String*-
imgs被拖走元素的占位图Base64 or url*-
imgPlaceStyle占位图的文字样式object-
initBoxWidth生成拖拽元素的初始宽度number*300
notListener是否不是监听者Booleantrue
initBoxHeight生成拖拽元素的初始高度number根据比例和宽度计算
dragNumber最大的拖拽数量number4
aspectRatio拖拽元素的比例string16:9
dragMinWidth生成拖拽元素的最小宽度number100
dragMaxWidth生成拖拽元素的最大宽度number根据比例和宽度计算
referBox动态计算比例的参照物stringbody
zIndex拖动元素的初始层级number100
emitTime改变窗口的事件节流事件number1000
canDrag设定当前是否可以拖动booleantrue

基础数据

id:被拖出元素的ID

index:拖拽盒子的层级

left:拖拽盒子的左边距

top:拖拽盒子的上边距

width:拖拽盒子的宽度

height:拖拽盒子的高度

parentWidth:参照盒子的宽度

parentHeight:参照盒子的高度度

事件

事件名描述回调参数
dragFull达到拖拽上限
drag-out有元素被拖出基础数据
drag-in有元素被拖回id
drag-move有元素被改变了位置基础数据
drag-zoom有元素被改变了大小基础数据
changeWidthAndHeight参照元素改变了宽高{parentHeight,parentWidth}
mouseUp鼠标松开取消移动过
mouseMoving鼠标正在移动
zIndexChange内部层级发生改变index

方法

方法名描述参数
sourceDrawDragBox源绘制数据,适用于操作者绘制之前的数据基础数据
setZIndex源设置当前的层级number
setSourceData监听者设定基础数据width,height
listenerDrawDragBox监听者绘制拖拽元素基础数据
listenersPutBackBox监听者放回元素id
listenersUpdateBox监听者更新拖拽元素基础数据
listenersIndexBox监听者改变层级基础数据
destroyById源销毁指定id元素id
destroyAll源销毁所有元素
setCanDrag设定当前是否可以拖动boolean
putBackDragBoxById放回指定元素源元素id string
1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.11

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.10

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.5

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago