Last active
August 29, 2015 14:04
-
-
Save stryju/1b7267f84512117bda3b to your computer and use it in GitHub Desktop.
d3 transition on nested groups
This file contains 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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>d3 transition on nested groups</title> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960; | |
var height = 500; | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g"); | |
var g1 = svg.append( 'g' ) | |
.attr( 'class', 'animated' ); | |
g1.append( 'rect' ) | |
.attr( 'width', 100 ) | |
.attr( 'height', 100 ); | |
var g2 = svg.append( 'g' ) | |
.attr( 'class', 'animated' ) | |
.attr( 'transform', 'translate( 150, 0 )' ); | |
g2.append( 'g' ) | |
.append( 'rect' ) | |
.attr( 'width', 100 ) | |
.attr( 'height', 100 ); | |
svg.selectAll( 'g.animated' ) | |
.style( 'opacity', 0 ) | |
.transition() | |
.duration( 1000 ) | |
.style( 'opacity', 1 ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment