Git Product home page Git Product logo

dragdrop's Introduction

设计思路

构造函数 DragBox

	属性:	ele
			isdraged  是否被拖拽
			dragbox   拖拽的对象
		drop    鼠标释放时自动调用的处理函数
	方法:
		setlisten	设置放下监听
		unsetlisten	取消放下监听

遇到的问题及解决方法

如何取消父元素的 drop 监听函数,并给新建的子元素添加 drop 函数

// 绑定监听函数,监听函数为对象自己的drop函数
$(document).bind("mouseup", this, this.drop);

// 取消自己的鼠标释放监听函数
$(document).unbind("mouseup", this.drop);

如何判读释放的是哪个元素?

尝试1: 给单独元素添加 onmouseup 事件监听函数

这样不行,因为释放鼠标时,盛放元素的盒子是不能捕获 鼠标抬起到事件。

【解决方法】

// 绑定监听函数,监听函数为对象自己的drop函数
$(document).bind("mouseup", this, this.drop);

jQuery 中 bind 是可以多个函数一起调用的。然后,通过bind的调用顺序是由绑定顺序来决定,后面绑定的先调用。

在创建的DOM元素对象中添加属性 isdraged 来区分,是哪个元素当前正在被拖拽:

// 是否被拖拽
this.ele.isdraged = false;
// 备份当前对象
this.ele.dragbox = this;

还需完善的工作

  1. 小窗口可以关闭,关闭后复原 初步思路: 在小窗口中添加关闭按钮,及关闭的事件处理函数

  2. 不止竖着添加,也可以横竖添加 初步思路: 在拖拽的对象中添加标记,下次采用哪种方式来添加

dragdrop's People

Contributors

jackproject avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.