1
I have a SVG image with the States of the Country and I need that when passing the mouse over a State, the image with the name of the State appears and follow the mouse.
I’ve already made the image appear and disappear with events mouseenter
and mouseleave
, however, I can’t make her follow the mouse inside the state with mousemove
.
Follows the code:
$('path.str0').mouseenter(function(){
var thisClass = $(this).attr('class');
var pieces = thisClass.split(' ');
//Estou mexendo aqui. Ewerton Melo
$('img').filter( '.' + pieces[2]).css("display", "block");
//Até aqui
$(this).attr('fill', "#00d4ff");
}).mousemove(function(e){
var mousex = e.pageX + 20; //Get X coodrinates
var mousey = e.pageY + 20; //Get Y coordinates
var tipWidth = $(this).width(); //Find width of tooltip
var tipHeight = $(this).height(); //Find height of tooltip
//Distance of element from the right edge of viewport
var tipVisX = $(window).width() - (mousex + tipWidth);
//Distance of element from the bottom of viewport
var tipVisY = $(window).height() - (mousey + tipHeight);
if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
mousex = e.pageX - tipWidth - 20;
} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
mousey = e.pageY - tipHeight - 20;
}
//Absolute position the tooltip according to mouse position
$(this).css({ top: mousey, left: mousex });
}).mouseleave(function(){
var thisClass = $(this).attr('class');
var pieces = thisClass.split(' ');
//console.log($('img').filter( '.' + pieces[2]).css("display", "none"));
$('img').filter( '.' + pieces[2]).css("display", "none");
$(this).attr('fill', "#00b2d6");
});
Javascript code is not enough. Also include SVG code and page HTML (
img
).– helderdarocha