Skip to content

Instantly share code, notes, and snippets.

@stepheneb
Forked from mbostock/.block
Created February 8, 2012 18:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stepheneb/1772079 to your computer and use it in GitHub Desktop.
Input Value Interpolation

This example uses a custom tween that interpolates the value property.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
padding: 40px;
}
input.h {
width: 600px;
height: 50px;
}
input.v {
width: 50px;
height: 400px;
-webkit-appearance: slider-vertical;
}
</style>
<input class="v" type="range" value="0" min="0" max="250" step="any" list="ticmarks">
<input class="h" type="range" value="0" min="0" max="250" step="any" list="ticmarks">
<datalist id="ticmarks">
<option value="0"></option>
<option value="50"></option>
<option value="100"></option>
<option value="150"></option>
<option value="200"></option>
<option value="250"></option>
</datalist>
<script src="http://mbostock.github.com/d3/d3.js?2.7.4"></script>
<script>
d3.selectAll("input").transition()
.delay(1000)
.duration(5000)
.tween("value", valueTween(250));
function valueTween(value) {
return function() {
var i = d3.interpolateNumber(this.value, value);
return function(t) { this.value = i(t); };
};
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment