当前位置:网站首页>day33 js笔记 事件(下)2021.09.28
day33 js笔记 事件(下)2021.09.28
2022-06-28 11:20:00 【即将成为大佬的小梦】
事件对象下的事件类型: e.type - 返回事件 比如:click contextmenu

事件对象下的鼠标信息:e.button (- 0 鼠标的左键 - 1 鼠标的滚轮 - 2 鼠标的右键)

事件对象下的键盘码:e.keyCode (回车键 13 - 空格 32 - 上下左右 37 38 39 40- 数字和字母是对应的ASCII)

获取设置元素的位置及大小方法:
- offsetTop/offsetLeft 元素距离浏览器顶部和左侧的间距(margin和定位影响)
- offsetWidth/offsetHeight 元素宽高(包含content+padding+border) margin不包含
- clientWidth/clientHeight 元素宽高(包含content+padding) 不包含border和margin
获取鼠标坐标点:
- offsetX/offsetY 鼠标在元素盒子里面的位置(不受任何属性影响)
- clientX/clientY 鼠标相对于浏览器的坐标位置(页面有滚动条的时候不受影响,可视区域坐标)
- pageX/pageY 鼠标相对于浏览器的坐标位置(页面有滚动条的时候受影响,加上滚动条的间距)

限制元素在一个范围内拖动:
- 获取当前浏览器的宽高大小 document.documentElement.clientHeight/clientWidth
获取元素盒子的宽高
- clientHeight/clientWidth 不包含边框的
- offsetWidth/offsetHeight 包含边框的

阻止默认事件:
- 在事件方法函数中的最后添加 return false
- e.preventDefault() 事件对象的方法
- 兼容写法: e.returnValue = false

事件委托:e.target (将自己的事情委托给父级去处理)

鼠标移出移入事件:
- onmouseover/onmouseout 触发冒泡
- onmouseenter/onmouseleave 不会触发冒泡

边栏推荐
猜你喜欢

AGCO AI frontier promotion (6.28)

New listing of operation light 3.0 - a sincere work of self subversion across the times!

功能真花哨,价格真便宜!长安全新SUV真实力到底怎样?

论文阅读 (59):Keyword-Based Diverse Image Retrieval with Variational Multiple Instance Graph

QML控件类型:TabBar

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system

day36 js笔记 ECMA6语法 2021.10.09

Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush

Characteristics of solar wireless LED display

JS foundation 3
随机推荐
GCC introduction
Mysql安装配置以及解决重装Mysql时忘记root password问题
选择哪种编程语言,会吸引优秀的人才?
Thesis reading (59):keyword based diverse image retrieval with variable multiple instance graph
字符串 & 堆 & 方法区
一套十万级TPS的IM综合消息系统的架构实践与思考
GCC简介
爱可可AI前沿推介(6.28)
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
Making and using of dynamic library (shared library)
Graduation season, some suggestions for you who are new to the society
Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
Oracle 日期格式化异常:无效数字
MySql5.7添加新用户
Introduction to GDB
[sword finger offer] 49 Ugly number
Wireshark数据抓包分析之FTP协议
方法重写(Override)
[function suggestion] select a space when multiple workspaces are started
Compareto() and equals() methods of BigDecimal class