-
Notifications
You must be signed in to change notification settings - Fork 0
/
world_visited.js
46 lines (37 loc) · 1.3 KB
/
world_visited.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
let places_visited = ['IN', 'AE', 'NP', 'GB', 'VN', 'BD'];
svg_countries = document.querySelectorAll("svg path");
// console.log(svg_countries);
for(let i = 0; i < places_visited.length; i++){
for(let j = 0; j < svg_countries.length; j++){
// svg_countries[j].style.stroke = 'rgb(255, 255, 255)';
if(places_visited[i].toString() == (svg_countries[j].id).toString()){
if (!svg_countries[j].hasAttribute('style')) {
svg_countries[j].setAttribute('style', '');
}
svg_countries[j].style.fill = 'rgb(100, 100, 200)';
}
}
}
let tooltip = document.getElementById("tooltip");
svg_countries.forEach(function(country) {
country.addEventListener('mouseover', function(event) {
// Retrieve the title attribute
let title = country.getAttribute('title');
// Set tooltip content
tooltip.innerHTML = title;
// Calculate the position relative to the cursor
const offsetX = 10;
const offsetY = 10;
const tooltipX = event.pageX + offsetX;
const tooltipY = event.pageY + offsetY;
// Set tooltip position
tooltip.style.left = tooltipX + 'px';
tooltip.style.top = tooltipY + 'px';
// Display tooltip
tooltip.style.display = 'block';
});
country.addEventListener('mouseout', function() {
// Hide tooltip on mouseout
tooltip.style.display = 'none';
});
});