Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stryju
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stryju/1b7267f84512117bda3b to your computer and use it in GitHub Desktop.
Save stryju/1b7267f84512117bda3b to your computer and use it in GitHub Desktop.
d3 transition on nested groups
<!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