1.0.3 • Published 2 years ago

dragmovablerea v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

特性

  • 支持pc和触摸设备
  • 支持拖拽和跨容器拖拽
  • 支持父容器放大
  • 不限制框架
  • 无其他依赖包
  • 支持移动实时获取坐标

安装

npm i dragmovablerea

引入

import Drag from 'dragmovablerea'

基础用法

<template>
    <div class="example-container">
        <div class="drag-container">
            <div class="left-menu">
                <ul class="list">
                    <li data-o="1111">aaaad</li>
                    <li data-o="2222">bbb</li>
                    <li data-o="3333">ccc</li>
                </ul>
            </div>
            <div id="moveWrapper" class="right-con">
                <div class="zoom-wrapper">
                    <template v-if="moveData.length > 0">
                        <div
                            v-for="(item, index) in moveData"
                            :key="index"
                            :style="'left:' + item.x + 'px;top:' + item.y + 'px'"
                            class="move-div"
                        >
                            <div class="close-div" />
                            {{ item.data }}</div>
                    </template>
                </div>
            </div>
        </div>
    </div>
</template>
<script>

import Drag from 'dragmovablerea'
export default {
    name: 'Example',
    data() {
        return {
            moveData: []
        }
    },
    computed: {
    },
    mounted() {
        this.$nextTick(() => {
            this.init()
        })
        setTimeout(() => {
            this.moveData = [
                { x: 10, y: 20 },
                { x: 20, y: 30 }
            ]
        }, 500)
    },
    methods: {
        init() {
            const DragUtil = new Drag('#moveWrapper', {
                getMoveData: (res) => {
                    this.moveData = res  // 回显x,y值
                }
            })
            const domArray = document.querySelectorAll('.left-menu li')
            Array.from(domArray).forEach(el => {
                const data = el.getAttribute('data-o')
                DragUtil.makeDraggable(el, data) // 为列表绑定拖拽事件
            })
        }
    }
}
</script>
<style lang="less" scoped>
.example-container{
    font-size: 14px;
    width: 70%;
    margin: auto;
    .list{
        li{
            height: 40px;
            line-height: 40px;
        }
    }
}
</style>

效果

image

属性

参数说明类型默认值
el可拖拽父容器String——
options配置项Object——

options配置项

参数说明类型默认值
scale放大比例Number1
isClick是否支持点击事件添加移动滑块Booleantrue
moveDivClass移动滑块样式String.move-div
delIconClass移动滑块删除图标样式String.close-div
getMoveData实时获取滑块位置等参数Function(data)data是回调值

事件

参数说明类型默认值
makeDraggable为某个dom绑定拖拽事件,可以放置到父容器中Function(el, data)el是当前dom元素,data是绑定当前dom的数据
setScale设置父容器放大比例Number1
1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago