event listener
-
DOM L0
<DOM>.on<type>=function(){}event will be cover
-
DOM L2
<DOM>.addEventListener('<type>',<functiion>)
type | 作用 |
---|---|
鼠标触发 | |
click | 鼠标点击 |
mousemove | 鼠标移动 |
mouseenter | 鼠标经过 |
mouseleave | 鼠标离开 |
表单获得光标 | |
focus | 获得焦距 |
blur | 失去焦距 |
键盘触发 | |
keydown | 键盘按下触发 |
keyup | 键盘抬起触发 |
表单输入触发 | |
input | 用户输入触发 |
event object
get
- The first cllback function bound to an event
- name rule:
event
e
<DOM>.addEventListener('<event>',function(<e>){})
attribute
-
type
-
clientX/ClientY
get the position of the cursor relative to the visible upper left corner of the browser
-
offsetX/offsetY
get the position of the cursor relative to the top left corner of the DOM element
-
key
the value of pressing a key
event flow
The complete proxess of event execution
event capturing
<DOM>
executes events starting from the root element (for inside out)
the third parameter of event monitoring is true
event bubbling
<DOM>
executes events starting from the outermost(from the outside in)
the third parameter of event monitoring is false or default
stop flow
<e>.stopPropagation()
prevent the flow of events
event unbinding
L0
<DOM>.on<operate> =null
L2
<DOM>.removeEventListener('<operate>',<function>)
mouse passong event
-
mode1
mouseobermouseoutthere will be bubbles
-
mode2(recommand)
mouserentermouseleave
difference in registration events
-
on
- using the same object,subsequent registrations will overwrite the previous object
- using null overwrite can unbind
- bubble phase execution
-
event listeners
-
grammar
addEventListener(<type>,<function>,[capture]) -
using the same object,subsequent registrations not will overwrite the previous object
-
the capture staage can be datemined by the third parameter
-
anonymous function cannoy unbind
-
event delegation
-
delegate object
entrusted to the parent element
-
searching for the truly triggered element
<e>.target
block default behavior
<e>.preventDefault()
loading event
-
triggered after loading external resources
event name:
load
-
after the html document is fully loaded and parsed
event name:
DOMcontentLoaded
scrolling event
evnet name:scroll
attribute scrolling
the value of movement
- scrollLeft
- scrollTop
- scrollTo(
<x>
,<y>
)
size event
event name:resize
attribute size
visible values
- clientWidth
- clientHeight
- offsetWidth(only read)
- offsetHeight(only read)
mobile terminal
screen touch | explain |
---|---|
touchstart | triggered when finger touches dom |
touchmove | triggered when the finger slides ona dom |
touchend | triggered when the finger moves away from a dom |