In a mousemove
event:
$(document).on('mousemove', function( e ){
console.log( e.pageX );
console.log( e.pageY );
});
as you can see, we can use pageX
and pageY
to get the x
and y
co-ordinates of mouse position. But, what I want is to trigger a custom event of mine on mousemove
and would like to get these pageX
and pageY
values in that custom event of mine. To be more clear, what I would like to do is:
$(document).on('mousemove', function(){
$(document).trigger('myevent');
});
$(document).on('myevent', function( e ){
// console.log( e.pageX );
// console.log( e.pageY );
});
Is there any way to access these pageX
and pageY
in myevent
?
.trigger()
allows to pass additional data via its arguments. You can call
$(document).on('mousemove', function( event ){
$(document).trigger('myevent', event);
});
Now you have access to the whole original event
object within your custom event code.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加