当前位置:网站首页>Mouse events in JS
Mouse events in JS
2022-07-02 04:39:00 【Da Da Q】
click: Click events .
dblclick: Double-click the event .
mousedown: Trigger when mouse button is pressed .
mouseup: Triggered when the pressed mouse button is released .
mousemove: Mouse movement events .
mouseover: Move in event .
mouseout: Remove Events .
mouseenter: Move in event .
mouseleave: Remove Events .
contextmenu: Right click events .
mouseover Events and mouseenter event , It is triggered when the mouse enters a node . The difference between the two ,mouseenter The event is triggered only once , As long as the mouse moves inside the node ,mouseover The event will trigger multiple times on the child node .
var div = document.getElementById("div")
var p = document.getElementById("p")
div.onmouseover=function(){
console.log("div")
}
p.onmouseover=function(){
console.log("p")
} // bubbling phase
div.onmouseenter=function(){
console.log("div")
}
p.onmouseenter=function(){
console.log("p")
} // Capture phase
Mouse event properties
MouseEvent.altKey
MouseEvent.ctrlKey
MouseEvent.metaKey
MouseEvent.shiftKey
Respectively represents when the mouse event occurs , Whether the corresponding keyboard key is pressed . Return value is Boolean .
document.body.onclick=function(e){
e=e||window.event
console.log("altKey:"+e.altKey); // Whether to press alt key
console.log("ctrlKey:"+e.ctrlKey); // Whether to press Ctrl key
console.log("metaKey:"+e.metaKey); // Whether to press meta key
console.log("shiftKey:"+e.shiftKey); // Whether to press shift key
}
MouseEvent.button Property returns a value , Indicates which mouse button was pressed when the event occurred .
0 For the left button
1 Represents the middle key
2 Right click
document.body.onmousedown=function(e){
e=e||window.event
console.log(e.button)
}
MouseEvent.clientX,MouseEvent.clientY
MouseEvent.clientX Property returns the horizontal coordinate of the mouse position relative to the upper left corner of the browser window ,
MouseEvent.clientY Property returns the vertical coordinate of the mouse position relative to the upper left corner of the browser window ,
Both properties are read-only .
document.body.onmousedown=function(e){
e=e||window.event
console.log(e.clientX,e.clientY)
}
MouseEvent.offsetX,MouseEvent.offsetY
MouseEvent.offsetX Property returns the horizontal distance between the mouse position and the left edge of the event object ,
MouseEvent.offsetY Property returns the vertical distance between the mouse position and the left edge of the event object ,
Both properties are read-only .
div.onclick=function(e){
e=e||window.event
console.log(e.offsetX,e.offsetY)
// When the mouse event is triggered , The distance between the current mouse position and the upper left corner of the target node
}
MouseEvent.pageX,MouseEvent.pageY
MouseEvent.pageX Property returns the distance between the mouse position and the left edge of the document ,
MouseEvent.pageY Property returns the distance from the mouse position to the top of the document .
Both properties are read-only .
document.body.onclick=function(e){
e=e||window.event
console.log("pageY:"+e.pageY) // From the top of the document
console.log("clientY:"+e.clientY) // From the top of the visual window
}
MouseEvent.movementX,MouseEvent.movementY( understand )
MouseEvent.movementX Property returns the previous mousemove Events and current mousemove Horizontal displacement between events ,
MouseEvent.movementY Property returns the previous mousemove Events and current mousemove The vertical distance of the event .
Both properties are read-only .
e.screenX,e,screenY
Horizontal and vertical distance from the screen
Mouse wheel events
The scroll event in Firefox is DOMMouseScroll, In other browsers onmousewheel.
Roll up and down and save to e.detail Inside
firefox :e.detail Drop too Oh
Scroll up to return a value greater than 0
Scroll down to return a value less than 0
Non Firefox :e.wheelDelta Take special
Scroll up to return a value less than 0
Scroll down to return a value greater than 0
function wheelEvent(e){
e=e||window.event
if(e.detail){ // Judge whether to support e.detail If you support it, it means Firefox
if(e.detail<0){
console.log(" Scroll up ")
}else{
console.log(" Scroll down ")
}
}else{ // I won't support it , Description is other browsers
if(e.wheelDelta<0){
console.log(" Scroll down ")
}else{
console.log(" Scroll up ")
}
}
}
document.body.onmousewheel=wheelEvent
document.body.addEventListener("mousewheel",wheelEvent) // Non Firefox
document.body.addEventListener("DOMMouseScroll",wheelEvent) // firefox
边栏推荐
- What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
- Let genuine SMS pressure measurement open source code
- Thinkphp Kernel wo system source Commercial Open source multi - user + multi - Customer Service + SMS + email notification
- Wechat applet JWT login issue token
- [C language] Dynamic Planning --- from entry to standing up
- [improvement class] st table to solve the interval maximum value problem [2]
- Mysql database learning
- Wechat applet map annotation
- Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
- C - derived classes and constructors
猜你喜欢
![[C language] Dynamic Planning --- from entry to standing up](/img/7e/29482c8f3970bb1a40240e975ef97f.png)
[C language] Dynamic Planning --- from entry to standing up

How to modify data file path in DM database

Keil compilation code of CY7C68013A

Pytoch --- use pytoch to predict birds

Pytoch --- use pytoch for image positioning

正大留4的主账户信息汇总

深圳打造全球“鸿蒙欧拉之城”将加快培育生态,优秀项目最高资助 1000 万元

Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market

Several methods of capturing packets under CS framework

万卷共知,一书一页总关情,TVP读书会带你突围阅读迷障!
随机推荐
初学爬虫-笔趣阁爬虫
Landing guide for "prohibit using select * as query field list"
Flag bits in assembly language: CF, PF, AF, ZF, SF, TF, if, DF, of
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
【提高课】ST表解决区间最值问题【2】
Keil compilation code of CY7C68013A
缓存一致性解决方案——改数据时如何保证缓存和数据库中数据的一致性
Beginner crawler - biqu Pavilion crawler
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
Ten thousand volumes are known to all, and one page of a book is always relevant. TVP reading club will take you through the reading puzzle!
6月书讯 | 9本新书上市,阵容强大,闭眼入!
Is it safe to open an account with first venture securities? I like to open an account. How can I open it?
AcrelEMS高速公路微电网能效管理平台与智能照明解决方案智慧点亮隧道
C - derived classes and constructors
Shutdown procedure after 60
【毕业季·进击的技术er】年少有梦,何惧彷徨
Gin framework learning code
Common locks in MySQL
A summary of common interview questions in 2022, including 25 technology stacks, has helped me successfully get an offer from Tencent
Handling of inconsistency between cursor and hinttext position in shutter textfield