Currently I have a arena map created with raphael, each svg element on the map has a tooltip when hovered over. The tooltip does not show on the first hover of an svg element, but it will show if the user enters the svg element again.
I assume it has something to do with my addTip "mouseeneter" function but I am still new with understanding JS so I am not sure. Here is the code I am using for adding the tooltip to the svg element on hover, the code I am using is based off of this stackoverflow forum question and the jsfiddle I have created link
var tip = $("#tip").hide();
var tipText = "Tip the Canoe.";
var over = false;
function addTip(node, txt)
{
$(node).mouseenter(function(){
tipText = txt;
tip.fadeIn();
over = true;
})
.mouseleave(function(){
tip.fadeOut();
over = false;
});
}
for (var i = 0, len = rsrGroups.length; i < len; i++) {
var el = rsrGroups[i];
el.mouseover(function() {
addTip(this.node, tipText);
console.log(node);
this.toFront();
this.attr({
cursor: 'pointer',
fill: '#990000',
});
//alert('test');
});
el.mousemove(function(e){
if (over){
tip.css("left", e.clientX+20).css("top", e.clientY+20);
tip.text(tipText);
}
});
el.mouseout(function() {
this.attr({
fill: '#003366'
});
});
el.click(function() {
this.attr({
fill: 'green'
});
});
}