html - Strange thing with onmousemove javascript -
hi guys:)if pass on div in example mouse's pointer function print in console 2 times,this menans onmousemove event triggered 2 times.i have printed coordinates of mouse's pointer , how can see in image below,i don't move verticallylly horizontally.how possible onmousemove event triggered considered div 1 pixel width?how possible onmousemove event triggered 2 times considered div 1 pixel width?
<div id="div1"> </div> #div1{ height:200px; width:1px; background:red; } document.getelementbyid("div1").onmousemove= function(){ console.log("in mousemove function"); console.log(event.clientx); console.log(event.clienty); };
you bind onmousemove
called every time mouse moved on element. when hover div move mouse down resolving in additional calls handler.
it more clear if add more width div.
what wants onmouseenter
called once when enter div:
document.getelementbyid('div1').addeventlistener('mouseenter', function() { console.log('mouse entered div'); });
Comments
Post a Comment