I need help creating a simple hover effect on a circle using jQuery. I'm facing an issue where the label location of the city overlaps with the circle when the mouse hovers over it. The label should be fixed in position on top of the red circle. Even when trying to describe a short-named city, the label overlapping remains unaddressed. For example:
const regionObject = {"philadelphia" : "Philadelphia",}
$(function(){
$('circle').mouseenter(function(e){
const circleId = $(this).attr('id');
const regionObject = {
"philadelphia" : "Philadelphia, a city in Pennsylvania",
}
var div = $(`<div class="current_region">
<div class="current_region_box">
<p>${regionObject[circleId]}</p>
</div>
<div class="region_pointer"></div>
</div>`)
.css({
"display": "block",
"left": (e.pageX - 40) + 'px',
"top": (e.pageY - 45) + 'px'
})
.appendTo(document.body);
}).mouseout(function(){
$('body').find('.current_region').remove();
});
});
.current_region {
position: absolute;
}
.current_region_box {
position: relative;
z-index: 10;
border-radius: 30px;
background: white;
box-shadow: 0px 2px 6px 1px rgba(18, 40, 112, 0.5);
padding: 4px 12px;
}
.current_region_box p {
font-family: firagolight;
font-size: 15px;
}
.current_region_box {
position: relative;
z-index: 10;
border-radius: 30px;
background: white;
box-shadow: 0px 2px 6px 1px rgba(18, 40, 112, 0.5);
padding: 4px 12px;
}
.current_region_box p {
font-family: firagolight;
font-size: 15px;
}
.region_pointer {
position: absolute;
z-index: 9;
bottom: -9px;
right: 3px;
left: 0;
margin: auto;
width: 25px;
height: 25px;
background: white;
border-radius: 5px;
transform: rotate(45deg);
box-shadow: 0px 0px 4px -1px grey;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Font Awesome -->
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Developer CSS -->
<link rel="stylesheet" type="text/css" href="./map.css">
<!-- Jquery-->
<script src="js/jquery-3.4.1.min.js"></script>
</head>
<body>
<div class="example" style="text-align: center; padding-top: 50px; cursor: pointer; " >
<svg height="100" width="100">
<circle id="philadelphia" cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
Sorry, your browser does not support inline SVG.
</svg>
</div>
<!--Bootstrap JS-->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity=" sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="./map.js"></script>
</body>
</html>