語法:
?let a = document.querySelector('.a')
? ? ? ? a.鼠標事件= function(){
? ? ? ? ? ? console.log('? ');
? ? ? ? }
鼠標事件:
(1)點擊事件:??onclick
(2)雙擊事件:??ondblclick
(3)鼠標右鍵點擊事件:???oncontextmenu
(4)鼠標進入事件:??onmouseenter? ? ?onmouseover
onmouseover 比 onmouseenter 先執(zhí)行
(5)鼠標離開事件:??onmouseleave? ? ??onmouseout
onmouseout 比 onmouseleave 先執(zhí)行
注意:如果元素里面存在子元素帜讲,鼠標在元素中移動時會反復觸發(fā) onmouseover 和 onmouseout
(6)鼠標移動事件 (所有的事件方法塌衰,都有一個默認的參數):? onmousemove
? ? ? ? ? 語法:
????????????????a.onmousemove = function(e){
? ? ? ? ? ? ????????//獲取鼠標指定位置
? ? ? ? ? ????????? let {offsetX,offsetY} = e
? ? ? ? ? ????? //conlose.log('鼠標移動',offsetX.offsetY)
? ? ? ? }
(7)鼠標按下事件 :? onmousedown
(8)鼠標彈起事件:? ?onmouseup
視口寬高
window.innerWidth 返回視口寬度
window.innerHeight 返回視口高度