Fuego DeBassi
Fuego DeBassi

Reputation: 3017

Multiple conditions before executing function

I call this function I have getMouseXY, whenever the mouse moves. Works great for tracking this element with the mouse. Like so:

document.onmousemove = getMouseXY;

But I'd like to layer in some logic, so it's only when the mouse is over this one element AND the mouse is moving. I thought this would work, but it doesn't:

document.getElementById("circle1").onmouseover && document.onmousemove = getMouseXY;

Any ideas? Help is much appreciated!

Upvotes: 1

Views: 37

Answers (1)

adeneo
adeneo

Reputation: 318302

You're probably looking for

document.getElementById("circle1").addEventListener('mousemove', getMouseXY);

which will fire whenever the mouse moves over the element with the ID #circle1

AWESOME FIDDLE

Upvotes: 2

Related Questions