This example demonstrates how to animate a path and a clipped textPath at the same time.
-
-
Save mbostock/3151318 to your computer and use it in GitHub Desktop.
Animated Clipped textPath
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
license: gpl-3.0 |
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> | |
<meta charset="utf-8"> | |
<style> | |
path { | |
fill: #3182bd; | |
} | |
text { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-size: 24px; | |
} | |
</style> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script> | |
var arc = d3.svg.arc() | |
.innerRadius(180) | |
.outerRadius(220) | |
.startAngle(0) | |
.endAngle(function(t) { return t * 2 * Math.PI / 3; }); | |
var svg = d3.select("body").append("svg") | |
.attr("width", 960) | |
.attr("height", 500) | |
.append("g") | |
.attr("transform", "translate(480,250)"); | |
svg.append("defs").append("path") | |
.attr("id", "text-path") | |
.attr("d", arc(1)); | |
svg.append("path") | |
.attr("id", "path"); | |
svg.append("clipPath") | |
.attr("id", "text-clip") | |
.append("use") | |
.attr("xlink:href", "#path"); | |
svg.append("text") | |
.attr("clip-path", "url(#text-clip)") | |
.attr("x", 8) | |
.attr("dy", 28) | |
.append("textPath") | |
.attr("xlink:href", "#text-path") | |
.text("Hello, curved textPath!"); | |
d3.select("#path").transition() | |
.duration(5000) | |
.attrTween("d", function() { return arc; }); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment