admin管理员组文章数量:1291300
Link to jsfiddle: /
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');
});
});
Link to jsfiddle: http://jsfiddle/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');
});
});
Share
Improve this question
edited Jun 27, 2013 at 13:50
Crisman
asked Jan 25, 2012 at 21:33
CrismanCrisman
4181 gold badge6 silver badges19 bronze badges
2
- I updated the fiddle after Greg Pettit's suggestions. Orginal: jsfiddle/crismanNoble/gqFdH/2 – Crisman Commented Jan 25, 2012 at 21:46
- It would be good to mention the update; it's confusing when you open it up, and it works alright. – Vlad Commented Jun 27, 2013 at 3:56
1 Answer
Reset to default 8Use .mouseenter()
and .mouseleave()
instead.
fiddle: http://jsfiddle/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.
本文标签: javascriptmouseover() event on SVG is acting weirdStack Overflow
版权声明:本文标题:javascript - .mouseover() event on SVG is acting weird - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741529078a2383644.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论