Ohr,
First, I installed Plunk , which achieves what you ask. Here is how I did it:
Js
$('document').ready(function () { $('#amount_to_rotate').keydown(function () { var el = $(".bottom_face"), amt = parseInt($(this).val()); rotZ = { '-webkit-transform': 'rotateX(-9deg) rotate(-10deg) translateZ(' + amt + 'px)', '-moz-transform' : 'rotateX(-9deg) rotate(-10deg) translateZ(' + amt + 'px)', } el.css(rotZ); }).keyup(function () { if ($(this).val().length == 0) {
More details
input has a keydown and keyup event keyup . When users enter a value, it is added to the object, and then added to the style attribute of the element through the jQuery css function. Using the object in this way allows you to set static values ββand pass a variable - in this case, amt - for the value of translateZ .
To be safe, since we are dealing with user input, we santize the input val() , pulling out only numbers: parseInt($(this).val());
It is also worth noting that I had to change the values ββthat you originally specified for the transformations, since rotateX(-90deg) flips the element along the x axis so that it becomes invisible. If this is your desired result, you can obviously change it to whatever you see fit.
Hope this helps.
source share