From 4e1d3ea10b4416e16cca4d327f3144fd335efd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 22 Aug 2019 18:36:22 +0800 Subject: [PATCH] update --- src/drag/core.js | 45 +++++++++++++++++++++++++++++++++++++++------ src/layer/next.wc | 3 ++- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/drag/core.js b/src/drag/core.js index fe8dbb2..6130e89 100644 --- a/src/drag/core.js +++ b/src/drag/core.js @@ -4,14 +4,47 @@ * @date 2019/08/21 17:28:40 */ -"use strict"; +'use strict' -export default Drag { - constructor(elem){ +import { bind, unbind } from '../utils' + +const log = console.log + +const DEF_OPT = { + axis: '', // x | y | xy 拖拽方向 + limit: false, // false | window | parent 拖拽范围 + overflow: true // 是否可拖拽出可视区外 +} + +export default class Drag { + constructor(elem) { this.$elem = elem } - by(node){ - + // drag by + by(node, opt = {}) { + this.$drag = node + this.opt = Object.assign(Object.create(null), DEF_OPT, opt) + + // + if (this.opt.limit !== false) { + this.opt.overflow = false + } + + // 鼠标状态图标 + var ico = document.documentMode ? 'move' : 'grab' + if (window.sidebar) { + ico = '-moz-' + ico + } else { + ico = '-webkit-' + ico + } + this.$drag.style.cursor = ico + + bind(this.$drag, 'mousedown', ev => { + var bcr = this.$elem.getBoundingClientRect() + log(bcr) + }) + + return this } -} \ No newline at end of file +} diff --git a/src/layer/next.wc b/src/layer/next.wc index cddeda5..872e084 100644 --- a/src/layer/next.wc +++ b/src/layer/next.wc @@ -112,7 +112,7 @@