Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.mouseover() event on SVG is acting weird

Link to jsfiddle: http://jsfiddle.net/crismanNoble/gqFdH/2/

Basically the svg keeps changing colors without ever triggering the .mouseout event.

$(function() {
    $(".icon")
    .mouseover(function() {
               var colors = ["#6F216C", "#F34B0D", "#C50102", "#5DA537", "#F1D81B"];
               var pick = Math.floor(Math.random()*5);
               var color = colors[pick];
               $(this).children().css('fill',color); 
               })
    .mouseout(function() {
              $(this).children().css('fill','black');
    });
});
like image 864
Crisman Avatar asked Feb 21 '23 17:02

Crisman


1 Answers

Use .mouseenter() and .mouseleave() instead.

fiddle: http://jsfiddle.net/gqFdH/5/

Without visiting the API docs, I suspect that .mouseover is triggered any time the mouse moves over (not just into) the area. But I could be making that up. I know that enter and leave work.

like image 157
Greg Pettit Avatar answered Mar 05 '23 10:03

Greg Pettit