I'm using jQuery to capture an event:
$('input').focus(function(e){
console.log( e.pageX, e.pageY );
});
This doesn't seem to work... any ideas on alternative ways to getting the mouse position?
Help would be great.
The focusout event fires when an element has lost focus, after the blur event. The two events differ in that focusout bubbles, while blur does not. The opposite of focusout is the focusin event, which fires when the element has received focus.
The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does bubble. The opposite of blur is the focus event, which fires when the element has received focus. The blur event is not cancelable.
The onblur event occurs when an object loses focus.
Events focus/blur The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an input field.
You can only get mouse coordinates using mouse events. If you want to capture the position of the mouse, you can use a global mousemove
event listener, and store the coordinates in a set of variables, which can later be accessed by the focus
function. Example:
var pageX, pageY; //Declare these globally
$(window).mousemove(function(e){
pagex = e.pageX;
pageY = e.pageY;
});
$('input').focus(function(){
console.log(pageX, pageY); // These variables have been defined by the global
// mousemove event
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With