Reputation: 127
i have a auto clicker that work with mouse position . here is the code :
var elem = document.elementFromPoint( x,y );
elem.addEventListener('click', function() {
console.log('clicked')
}, false);
var support = true;
try {
if (new MouseEvent('click', {bubbles: false}).bubbles !== false) {
support = false;
} else if (new MouseEvent('click', {bubbles: true}).bubbles !== true) {
support = false;
}
} catch (e) {
support = false;
}
setInterval(function() {
if (support) {
var event = new MouseEvent('click');
}else{
var event = document.createEvent('Event');
event.initEvent('click', true, true);
}
elem.dispatchEvent(event);
},1000);
and i also have code for get mouse position :
var cursorX;
var cursorY;
document.onmousemove = function(e){
cursorX = e.pageX;
cursorY = e.pageY;
}
setInterval("checkCursor()", 1000);
function checkCursor(){
alert( cursorX + ","+ cursorY);
}
and my questions is : how can i put mouse position in document.elementFromPoint(x,y ) ????
i know can put my x and y but i want to x and y update when i move mouse anywhere
Upvotes: 1
Views: 171
Reputation: 1931
Edit
You actually need to initialize elem
and cursorX
and cursorY
first, sorry, didn't test this code.
Declare elem as a variable
var elem = document.elementFromPoint( cursorX,cursorY );
And initialize cursors cursorX = 0; cursorY = 0
Then inside your mousemove function, do this
document.onmousemove = function(e) {
cursorX = e.pageX;
cursorY = e.pageY;
elem = document.elementFromPoint(e.pageX, e.pageY);
}
Upvotes: 1