Where to put my missing .mouseover() to get the mouse position? (jquery)
After some reading from this tutorial, I have the following partly working code:
$(document).bind ("found_match", function(e){
$('#开发者_C百科status2').html(e.pageX +', '+ e.pageY);
});
When the event: "found_match happens", it should show the mouse coordinates in the div: "status2", but it doesn't. Obviously because I am missing the .mousover(). But where to put this in my code to make it work so that it wil show the mouse coordinates the moment this event happened?
Many thanks
Try this:
$('#someID').mousemove(function(event){
$(document).trigger('found_match', event);
});
Here is a fiddle example: http://jsfiddle.net/maniator/M3FwY/
(I had to change the parameters of your custom function a bit)
found_match
is a custom event. You, the programmer need to trigger
that event at some point.
$('#foo').mousemove(function (e)
{
if (someCondition) // probably involving e.pageX and e.pageY
{
$(document).trigger('found_match');
}
});
精彩评论