Last active
December 16, 2015 04:39
-
-
Save fidothe/5378483 to your computer and use it in GitHub Desktop.
demonstrate d3.behavior.zoom tap-eating
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
<html> | |
<head> | |
<title>tap eating</title> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var svg = d3.select('body').append('svg') | |
.attr('width', width) | |
.attr('height', height); | |
svg.append('g').append('rect') | |
.attr('x', 200) | |
.attr('y', 200) | |
.attr('width', 100) | |
.attr('height', 100) | |
.attr('fill', 'black') | |
.on('click', function() { | |
var node = d3.select(this); | |
if (node.attr('fill') == 'black') { | |
node.attr('fill', 'red'); | |
} | |
else { | |
node.attr('fill', 'black'); | |
} | |
}); | |
var g = d3.select('g'); | |
var zoom = d3.behavior.zoom(); | |
zoom.on('zoom', function() { | |
g.attr('transform', 'translate(' + d3.event.translate[0] + ',' + d3.event.translate[1] + ')'); | |
}) | |
svg.call(zoom) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment