Skip to content

Instantly share code, notes, and snippets.

@jonathanhculver
Created January 23, 2014 02:38
Show Gist options
  • Save jonathanhculver/8571878 to your computer and use it in GitHub Desktop.
Save jonathanhculver/8571878 to your computer and use it in GitHub Desktop.
tape measure JS
/* click and drag */
new Draggable('tape_measure_drag', { constraint: 'horizontal', handle: 'tape_measure_drag',
onDrag: function(e) {
var offset = $('tape_measure_drag').positionedOffset().left;
var value = ((offset-140)/80)*-1;
value = (Math.round(value * 4) / 4).toFixed(2);
if(value > 0) {
$('measurementInput').value = value;
}
},
snap: function(y) {
return [(y < 140) ? (y > -6260 ? y : -6260) : 140 ];
}
});
/* input box interaction */
$('measurementInput').observe('keyup', function(e) {
$('tape_measure_drag').style.transition = 'left .5s ease 0s';
var offset = $('tape_measure_drag').positionedOffset().left;
var value = this.value;
value = (Math.round(value * 4) / 4).toFixed(2);
offset = -1*((value*80)-140);
$('tape_measure_drag').style.left = (offset)+"px";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment