block by jalapic b204a516ca35e10fe165

Slider Control

Full Screen

Built with blockbuilder.org

Using a slider to control the radius of a circle. First simple example to get started.

forked from jfost00‘s block: Slider Control

index.html

<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
  <style>
    body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
    svg { width:100%; height: 100% }
  </style>
</head>

<body>
  <h1>Use the slider to control the radius of the circle:</h1>
  <input type="range" min="1" max="150" id="nRadius">
  <script>
    
    d3.select("#nRadius").on("input", function() {
  	update(+this.value);
		});
    function update(nRadius) {

  	// adjust the text on the range slider
  	d3.select("#nRadius-value").text(nRadius);
  	d3.select("#nRadius").property("value", nRadius);

  	// update the circle radius
  	svg.selectAll("circle") 
    .attr("r", nRadius);
		}

    // Feel free to change or delete any of the code you see!
    var svg = d3.select("body").append("svg")
    svg.append("circle")
      .attr({cx: 200, cy: 200, r: 100})
      .style({ fill: "#5e91e2"})
    console.log("you are now rocking with d3", d3);
  </script>
</body>