HTML onmouseover 事件屬性


HTML onmouseover 事件屬性是在滑鼠指標移動到 HTML 文件中的 HTML 元素時觸發的。

語法

以下是語法 −

<tagname onmouseover=”script”></tagname>

來看一個 HTML onmouseover 事件屬性的示例−

示例

 實際演示

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      height: 100vh;
      background-color: #FBAB7E;
      background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
      text-align: center;
   }
   .circle {
      background: #db133a;
      height: 150px;
      width: 150px;
      border-radius: 50%;
      margin: 10px auto;
   }
   p {
      margin: 30px auto;
   }
</style>
</head>
<body>
<h1>HTML onmouseover Event Attribute Demo</h1>
<div class="circle" onmousemove="mouseMoveFn()" onmouseout="mouseOutFn()"></div>
<p>Try to move the cursor over the red circle</p>
<script>
   function mouseMoveFn() {
      document.querySelector('.circle').style.background = '#2274A5';
   }
   function mouseOutFn() {
      document.querySelector('.circle').style.background = '#0B6E4F';
   }
</script>
</body>
</html>

輸出

現在嘗試將滑鼠游標移動到紅圈上,觀察 onmouseout 事件屬性如何工作−


更新日期: 2019 年 9 月 27 日

500 人瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告