D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
adry34160
Full window
Github gist
18 - Interactive text rotation with d3.js
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <p> <label for="nAngle" style="display: inline-block; width: 240px; text-align: right"> angle = <span id="nAngle-value">...</span> </label> <input type="range" min="0" max="360" id="nAngle"> </p> <script> var width = 600; var height = 300; var holder = d3.select("body") .append("svg") .attr("width", width) .attr("height", height); // draw the text holder.append("text") .style("fill", "black") .style("font-size", "56px") .attr("dy", ".35em") .attr("text-anchor", "middle") .attr("transform", "translate(300,150) rotate(0)") .text("letitbi.net"); // when the input range changes update the angle d3.select("#nAngle").on("input", function() { update(+this.value); }) // initial starting angle of the text update(0); function update(nAngle) { //adjust the text on the range slicer d3.select("#nAngle-value").text(nAngle); d3.select("#nAngle").property("value", nAngle); // rotate the text holder.select("text") .attr("transform", "translate(300, 150) rotate("+nAngle+")"); } </script>
https://d3js.org/d3.v4.min.js