onmousemove-händelse

Definition och användning

onmousemove-händelsen inträffar när pekpikaren rör sig över elementet .

Exempel

Exempel 1

Uppföra JavaScript när muspekaren är över <div>-elementet:

<div onmousemove="myFunction()">Flytta muspekaren över mig</div>

Try it yourself

Example 2

This example demonstrates the difference between onmousemove, onmouseenter, and mouseover events:

<div onmousemove="myMoveFunction()">
  <p id="demo">I will demonstrate onmousemove!</p>
</div>
<div onmouseenter="myEnterFunction()">
  <p id="demo2">I will demonstrate onmouseenter!</p>
</div>
<div onmouseover="myOverFunction()">
  <p id="demo3">I will demonstrate onmouseover!</p>
</div>

Try it yourself

Example 3

This example demonstrates the difference between onmousemove, onmouseleave, and onmouseout events:

<div onmousemove="myMoveFunction()">
  <p id="demo">I will demonstrate onmousemove!</p>
</div>
<div onmouseleave="myLeaveFunction()">
  <p id="demo2">I will demonstrate onmouseleave!</p>
</div>
<div onmouseout="myOutFunction()">
  <p id="demo3">I will demonstrate onmouseout!</p>
</div>

Try it yourself

Syntax

In HTML:

<element onmousemove="myScript">

Try it yourself

In JavaScript:

object.onmousemove = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("mousemove", myScript);

Try it yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.

Technical details

Bubbling: Stöd
Cancellable: Stöd
Event types: MouseEvent
Supported HTML tags: All HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> and <title>
DOM-version: Level 2 Events

Webbläsarstöd

Händelser Chrome IE Firefox Safari Opera
onmousemove Stöd Stöd Stöd Stöd Stöd