Created
November 24, 2015 01:59
-
-
Save d3byex/94928c18fb39479df6de to your computer and use it in GitHub Desktop.
D3byEX 8.2: Mouse Enter and Exit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="D3byEX 8.2" /> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var svg = d3.select('body').append('svg') | |
.attr({ 'width': 600, 'height': 600 }); | |
var data = [30, 20, 40], x = 0; | |
svg.selectAll('circle') | |
.data(data) | |
.enter() | |
.append('circle') | |
.attr('fill', 'steelblue') | |
.each(function(d, i) { | |
d3.select(this).attr({ | |
cx: x += (d + 5), | |
cy: 40, | |
r: d / 2 | |
}); | |
}) | |
.on('mouseenter', function() { | |
d3.select(this).attr('fill', 'red'); | |
}) | |
.on('mouseout', function() { | |
d3.select(this).attr('fill', 'steelblue'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment