EventTarget事件:mouseover

2019-01-24 16:02 更新

EventTarget事件 - mouseover

將mouseover指針設(shè)備移動到附加了偵聽器的元素或其子節(jié)點(diǎn)之一上時會觸發(fā)該事件。

基本信息

規(guī)范DOM L3 
接口MouseEvent
是否冒泡
是否可取消
目標(biāo)Element
默認(rèn)操作沒有

屬性

屬性類型描述
target(只讀)EventTarget事件目標(biāo)(DOM樹中最頂層的目標(biāo))。
type(只讀)DOMString事件的類型。
bubbles(只讀)Boolean
事件是否正常冒泡
cancelable(只讀)Boolean事件是否可以取消
view(只讀)WindowProxydocument.defaultViewwindow文件)
detail(只讀)longfloat0。
currentTarget(只讀)EventTarget附加了事件監(jiān)聽器的節(jié)??點(diǎn)。
relatedTarget(只讀)EventTarget對于mouseover,mouseout,mouseentermouseleave事件:互補(bǔ)事件的目標(biāo)(在mouseenter事件的情況下為mouseleave目標(biāo))。否則為null。 
screenX(只讀)long
全局(屏幕)坐標(biāo)中鼠標(biāo)指針的X坐標(biāo)。
screenY(只讀)long
全局(屏幕)坐標(biāo)中鼠標(biāo)指針的Y坐標(biāo)。
clientX(只讀)long
鼠標(biāo)指針在本地(DOM內(nèi)容)坐標(biāo)中的X坐標(biāo)。
clientY(只讀)long
鼠標(biāo)指針在本地(DOM內(nèi)容)坐標(biāo)中的Y坐標(biāo)。
button(只讀)unsigned short
這始終為0,因為沒有按鈕按下此事件(鼠標(biāo)移動)。
buttons(只讀)unsigned short
觸發(fā)鼠標(biāo)事件時按下按鈕:左按鈕= 1,右按鈕= 2,中間(滾輪)按鈕= 4,第4按鈕(通常,“瀏覽器返回”按鈕)= 8,第5按鈕(通常為“瀏覽器”轉(zhuǎn)發(fā)“按鈕”= 16。如果按下兩個或更多按鈕,則返回值的邏輯和。例如,如果按下左鍵和右鍵,則返回3(= 1 | 2)。
mozPressure(只讀)float
生成事件時施加到觸摸或制表設(shè)備的壓力量;此值介于 0.0 (最小壓力) 和 1.0 (最大壓力) 之間。
ctrlKey(只讀)boolean
如果在觸發(fā)事件時控制鍵已關(guān)閉,則為true,否則為false
shiftKey(只讀)boolean
如果在事件被觸發(fā)時shift鍵已關(guān)閉,則為true,否則為false。
altKey(只讀)boolean
如果事件被觸發(fā)時alt鍵已關(guān)閉,則為true,否則為false
metaKey(只讀)boolean
如果在觸發(fā)事件時meta鍵已關(guān)閉,則為true,否則為false。

示例

以下示例說明了mouseover和mouseenter事件之間的區(qū)別。

<ul id="test">
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
</ul>

<script>
  var test = document.getElementById("test");
  
  
  // this handler will be executed only once when the cursor moves over the unordered list
  test.addEventListener("mouseenter", function( event ) {   
    // highlight the mouseenter target
    event.target.style.color = "purple";

    // reset the color after a short delay
    setTimeout(function() {
      event.target.style.color = "";
    }, 500);
  }, false);
  
  
  // this handler will be executed every time the cursor is moved over a different list item
  test.addEventListener("mouseover", function( event ) {   
    // highlight the mouseover target
    event.target.style.color = "orange";

    // reset the color after a short delay
    setTimeout(function() {
      event.target.style.color = "";
    }, 500);
  }, false);
</script>

瀏覽器兼容性

我們將兼容性數(shù)據(jù)轉(zhuǎn)換為機(jī)器可讀的JSON格式。

  • 電腦端

Chrome
Firefox(Gecko)Internet Explorer
Edge
Opera
Safari
基本支持支持支持支持支持支持支持
在禁用的表單元素上支持[1]支持:44.0[2]支持不支持支持[1]
  • 移動端

AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
基本支持?支持????
在禁用的表單元素上
?不支持????

注釋:

[1]僅適用于<textarea>元素和某些<input>元素類型。

[2]在錯誤218093中實現(xiàn)。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號