当前位置:网站首页>拖放事件,dataTransfer,getBoundingClientRect
拖放事件,dataTransfer,getBoundingClientRect
2022-07-30 10:00:00 【飞奔的马铃猫】
最近要写一个lowcode项目,对于我这个只写过网页项目的人来说,真的是啥也不会啊。看了一个项目的源码,看这里的东西好好学习一下,顺便复习一下原来的东西。QAQ
首先是
从没用过的拖拽
拖放事件
拖放事件中有三种对象。
- 源对象:过程中被拖放的对象
- 过程对象:拖放中经过的对象
- 目标对象:最终到达的对象
这三种对象有其不同的触发事件
源对象
dragstart:开始拖放,开始移动时事件触发。drag:拖放过程中,移动被拖拽对象时触发。dragend:拖放结束,整个拖放操作结束时触发。
过程对象
dragenter:源对象进入过程对象范围内,被拖拽对象进入过程对象时被触发dragover:源对象在过程对象范围内移动,被拖拽对象在过程对象内移动时触发dragleave:源对象离开过程对象的范围,被拖拽对象离开目标对象时触发
目标对象:
drop:在目标对象内松手时触发。
dataTransfer对象
在所有的拖放事件中都提供了一个数据传输对象dataTransfer,主要是用于在源对象和目标对象之间传递数据。
方法
setData(format, data)
设置拖拽事件中要传递的数据,
format的参数为数据类型该方法向
dataTransfer中对象中存入数据,接受两个参数,第一个表示要存入的数据类型,共有4种:- text/plain
- text/html
- text/xml
- text/uri-list
- 如果写入的参数不是上面这几种,就相当于新创了一个数据类型。使得
dataTransfer.types列表中的最后一个项目将是新类型。
参数2是要存入的数据
例:
e.dataTransfer.setData("num",index)
getData(format)
- 获得拖拽事件中传递的数据,
format参数为数据类型 - 该方法从
dataTransfer对象中读取数据,参数为在setData方法中指定的数据类型,例如:event.dataTransfer.getData('text/plain')
- 获得拖拽事件中传递的数据,
clearData()
- 有参数:清空该参数对应存储的数据
- 无参数:清空所有数据
getBoundingClientRect()
Element.getBoundingClientRect() 方法返回元素的大小及其相对于视口(电脑屏幕)的位置。
连带复习:
clientX:当鼠标事件发生时,鼠标相对于浏览器(浏览器上显示页面得位置)X轴的位置;
clientY:当鼠标事件发生时,鼠标相对于浏览器y轴的位置;
screenX:当鼠标事件发生时,鼠标相对于显示器屏幕x轴的位置;
screenY:当鼠标事件发生时,鼠标相对于显示器屏幕y轴的位置;
offsetX:当鼠标事件发生时,鼠标相对于事件源x轴的位置
offsetY:当鼠标事件发生时,鼠标相对于事件源y轴的位置
\
边栏推荐
- Multi-threading scheme to ensure that a single thread opens a transaction and takes effect
- 多线程保证单个线程开启事务并生效的方案
- WARN: Establishing SSL connection without server's identity verification is not recommended when connecting to mysql
- Flink_CDC搭建及简单使用
- 时刻铭记:总有一天你将破蛹而出
- Js array operating mobile for encapsulation
- Materialist Dialectics - Conditionalism
- SST-Calib: A lidar-visual extrinsic parameter calibration method combining semantics and VO for spatiotemporal synchronization calibration (ITSC 2022)
- 电压跟随器不要随便加
- Array of Shell System Learning
猜你喜欢

Flask's routing (app.route) detailed

spark udf accepts and handles null values.

线程池方式开启线程--submit()和execute()的区别

Re15: Read the paper LEVEN: A Large-Scale Chinese Legal Event Detection Dataset

A near-perfect Unity full-platform hot update solution

By building a sequence table - teach you to calculate time complexity and space complexity (including recursion)

Meikle Studio-Look at Hongmeng Device Development Practical Notes 7-Network Application Development

Re15:读论文 LEVEN: A Large-Scale Chinese Legal Event Detection Dataset

Nacos configuration in the project of battle

Re19:读论文 Paragraph-level Rationale Extraction through Regularization: A case study on European Court
随机推荐
CVTE school recruitment written test questions + summary of knowledge points
Flask's routing (app.route) detailed
多线程保证单个线程开启事务并生效的方案
flowable工作流所有业务概念
hcip06 ospf special area comprehensive experiment
flyway的快速入门教程
JVM内存布局、类加载机制及垃圾回收机制详解
If someone asks you about distributed transactions again, throw this to him
JCL 学习
idea2021+Activiti【最完整笔记一(基础使用)】
Re19:读论文 Paragraph-level Rationale Extraction through Regularization: A case study on European Court
【HMS core】【FAQ】HMS Toolkit典型问题合集1
SST-Calib:结合语义和VO进行时空同步校准的lidar-visual外参标定方法(ITSC 2022)
Baidu promotion assistant encounters duplicate keywords, verification errors, how to delete redundant ones with one click
判断一颗树是否为完全二叉树——视频讲解!!!
Day113. Shangyitong: WeChat login QR code, login callback interface
105. Construct binary tree from preorder and inorder traversal sequence (video explanation!!)
一个近乎完美的 Unity 全平台热更方案
New in GNOME: Warn users when Secure Boot is disabled
The creation of a large root heap (video explanation)