這是在Greensock論壇上提供給我的答案。
console.clear();
var output = document.getElementById('output');
var temp = document.getElementById('temperature');
var previousRotation = 0;
//from Blake
function normalize(value, min, max) {
return (value - min)/(max - min);
}
//from Chrysto
function percentToRange(percent, min, max) {
return((max - min) * percent + min);
}
Draggable.create('#dial', {
type:'rotation',
throwProps: true,
bounds: {
minRotation: 0,
maxRotation: -180
},
onDrag: function(){
var normalized = normalize(this.rotation, 0, -180);
var mapped = percentToRange(normalized, 18, 26);
console.log(this.rotation, normalized, mapped, this.getDirection());
temp.innerHTML = parseInt(mapped);
}
});
http://codepen.io/GreenSock/pen/ALNzJz?editors=0011