Is it possible to change certain timeline / tween properties through JavaScript.
So let’s say I have a Cube that spins 360 degrees in 1 second (timeline). And I have a button that randomises the rotation. When I press the button the Cube now spins a random number of degrees (0 - 360).
A follow-up question would be: is there a way to tween objects using the Hype-JS-library directly (so without the timeline)?
If you are looking to programmatically change the rotation then you can access the transform property like so
element.style.transform = ...
So, maybe in your case you can do something like this in a function on click
var randNum = Math.floor(Math.random() * 360) + 1; // generates a random number between 1 and 360.
cube = hypeDocument.getElementById('myCube'); //points to your element with an ID of "myCube"
cube.style.transition = "transform 1s"; //this animates it over 1 sec
cube.style.transform = "translateX(100px) translateY(100px) rotate(" + randNum + "deg)"; // The setting for the transform property of your element to spin on the z axis randomly. You can add the rotateX and rotateY values in the same way. Note the translate values must be the same as your left and top position in Hype scene otherwise the element will go to the 0,0 corner
I sure do It’s wasn’t meant as a rude comment, just a tiny remark for people who might blindly copy-paste your code
I haven’t looked that much into CSS animations yet, so that might be why I missed the reference to the basic CSS techniques (I always use(d) JS for animation). I’ll definitely have a look then.
Note that you can use Hype’s animation system to animate properties in a similar manner to the CSS Transitions shown above. When using the Hype runtime, Hype is aware of the changes which might be required depending what else your animation is doing (like if there are other timelines/actions that may affect the elements).
You can feed values like:
var randNum = Math.floor(Math.random() * 360) + 1; // generates a random number between 1 and 360.
cube = hypeDocument.getElementById('myCube'); //points to your element with an ID of "myCube"
hypeDocument.setElementProperty(cube, 'rotateZ', randNum, 1.0, 'easeinout');
It works! However, I have the following issue. As soon as I resize my window so that a different layout triggers, the animation stops. If I make a time-line animation, I can switch between layouts without any problems.
Is there a way to force the animation to continue on a layout-switch? Or is there a way to change the properties of a timeline animation?