Export Code
Connected
index.html
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.province {
fill: #000;
stroke: #fff;
stroke-width: 1px;
}
.province:hover {
fill: #666;
}
.hidden {
display: none;
}
div.tooltip {
color: #222;
background-color: #fff;
padding: .5em;
text-shadow: #f5f5f5
Alt + Click on a hex color
Open a color picker to modify the color
0 1px 0;
border-radius: 2px;
opacity: 0.9;
position: absolute;
}
</style>
<body>
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 690,
height = 500;
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height);
var tooltip = d3.select('body').append('div')
.attr('class', 'hidden tooltip');

Map hover

Aurélien

Last edited Dec 01, 2021
Created on Dec 01, 2021
Forked from Hello VizHub

An example showing hovering on a map:

  • Loads d3v7 via UNPKG.
  • Loads map of Canada
  • On mouse move :
    • shows a div by modifying its css properties
    • modifies the content and position of a div (the tooltip)
    • changes the css class of the state to change its color
  • On mouse out :
    • hides the tooltip div
MIT Licensed