<p>This method is a shortcut for <code>.bind('mousemove', handler)</code> in the first variation, and <code>.trigger('mousemove')</code> in the second.</p>
<p>The <code>mousemove</code> event is sent to an element when the mouse pointer moves inside the element. Any HTML element can receive this event.</p>
<p>Now when the mouse pointer moves within the target button, the messages are appended to <div id="log">:</p>
<p>
<spanclass="output">Handler for .mousemove() called at (399, 48)</span><br><spanclass="output">Handler for .mousemove() called at (398, 46)</span><br><spanclass="output">Handler for .mousemove() called at (397, 44)</span><br><spanclass="output">Handler for .mousemove() called at (396, 42)</span><br></p>
<p>We can also trigger the event when the second button is clicked:</p>
<pre>$('#other').click(function() {
$('#target').mousemove();
});</pre>
<p>After this code executes, clicks on the Trigger button will also append the message:</p>
<p><spanclass="output">Handler for .mousemove() called at (undefined, undefined)</span></p>
<p>When tracking mouse movement, we usually need to know the actual position of the mouse pointer. The event object that is passed to the handler contains some information about the mouse coordinates. Properties such as <code>.clientX</code>, <code>.offsetX</code>, and <code>.pageX</code> are available, but support for them differs between browsers. Fortunately, jQuery normalizes the <code>.pageX</code> and <code>.pageY</code> attributes so that they can be used in all browsers. These attributes provide the X and Y coordinates of the mouse pointer relative to the top-left corner of the page, as illustrated in the example output above.</p>
<p>We need to remember that the <code>mousemove</code> event is triggered whenever the mouse pointer moves, even for a pixel. This means that hundreds of events can be generated over a very small amount of time. If the handler has to do any significant processing, or if multiple handlers for the event exist, this can be a serious performance drain on the browser. It is important, therefore, to optimize <code>mousemove </code>handlers as much as possible, and to unbind them as soon as they are no longer needed.</p>
<p>A common pattern is to bind the <code>mousemove</code> handler from within a <code>mousedown</code> hander, and to unbind it from a corresponding <code>mouseup</code> handler. If implementing this sequence of events, remember that the <code>mouseup</code> event might be sent to a different HTML element than the <code>mousemove</code> event was. To account for this, the <code>mouseup</code> handler should typically be bound to an element high up in the DOM tree, such as <code><body></code>.</p>
<h4><spanclass="desc">Show the mouse coordinates when the mouse is moved over the yellow div. Coordinates are relative to the window, which in this case is the iframe.</span></h4>