当前位置:网站首页>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 不会触发冒泡

边栏推荐
- js中this的默认指向及如何修改指向 2021.11.09
- Scientific research - web of science retrieval skills
- 无法重新声明块范围变量
- 《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!
- Graduation season, some suggestions for you who are new to the society
- soapui的菜鸟教程
- Making and using of static library
- 时间戳和date转换「建议收藏」
- Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
- GCC introduction
猜你喜欢

Docker modifies the user name and password of MySQL

TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush

动态库(共享库)的制作和使用

Yann LeCun新论文:构建自动智能体之路
This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors

太阳能无线LED显示屏的特点

For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?

利用soapUI获取freemarker的ftl文件模板

JS foundation 1-js introduction and operator

day39 原型链及页面烟花效果 2021.10.13
随机推荐
MySql5.7添加新用户
【sciter】: sciter-fs模块扫描文件API的使用及其注意细节
Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
AGCO AI frontier promotion (6.28)
一套十万级TPS的IM综合消息系统的架构实践与思考
Debug debugging in katalon
合约量化交易系统开发 | 合约量化APP开发(现成案例)
静态库的制作和使用
Training notice | special training notice on epidemic prevention and security prevention for overseas Chinese funded enterprises, institutions and personnel in 2022
Redis6 一:Nosql引入、Redis可以解决什么问题?
Get current system date
Metersphere implements UI automation elements that are not clickable (partially occluded)
String & heap & method area
近况
GCC简介
获取系统当前日期
字符串 & 堆 & 方法区
vsftpd服务的部署及优化
[sciter]:sciter如何使用i18实现桌面应用多语言切换及其利弊
Making and using of dynamic library (shared library)