Get mouse position when focus/blur events are fired?

前端 未结 2 1156
一整个雨季
一整个雨季 2021-01-18 02:04

I\'m using jQuery to capture an event:

$(\'input\').focus(function(e){

    console.log( e.pageX, e.pageY );

});

This doesn\'t seem to work.

2条回答
  •  情话喂你
    2021-01-18 02:36

    If you're trying to get the position relative to the element, try something like this instead:

    $("input").focus(function(e){
        var relativeX = e.pageX - this.offsetLeft;
        var relativeY = e.pageY - this.offsetTop;
    });
    

提交回复
热议问题