Thanks. That is working.
But I am having a doubt. Won’t this create a problem as you are calling requestAnimationFrame(mainLoop);
Without knowing if the tween to increment the angle by 6 degrees has completed or not?
And why there is a “0” in place of time? Is it a typo? I am confused since even if it’s a typo it’s working?
This is a common looping tactic using requestAnimationFrame. On each recursion the “val1” variable will always increase by 6 until you call cancelAnimationFrame() to cancel the “looping”.
The 0 is not a typo it’s just left there to show you that the animation with start immediately. If for example you put in 1.0 (1sec) it will start off slowly then resume at the same speed. Whichever is the preferred effect.
This is by no means a finished example. It’s just to show you a way to “infinitely” loop your animation.
No, because be 4th argument must be the duration. Additionally there’s no point to having a timing function without a duration since it will just be applied instantly.
(you are missing a comma and closing parenthesis, so it will probably cause a syntax error first )
It will cause a 2.0 second animation with an 'easeinout' timing function (the default if left unspecified).
Basically if a optionalDuration is given to setElementProperty, it creates an ad-hoc timeline animating that property. If no duration is given, it immediately changes the value.
I don’t mean to be flippant but ok comma aside (my bad as I missed filling it in) I was simply pointing out to the OP the way he added the animation so as not to be too confusing. I of course understand the way you’ve done it with the API and the order of parameters but for clarities sake I was making it (maybe) clearer for the OP.
Also, and definitely off topic, I may have had a few too many drinks as my team (country) just won the Grand Slam (local … to the UK) rugby tournament so I’m definitely not firing on all cylinders
Thank you, this is very useful for any project, so how do you make an x or y rotation?
I’m trying with this one but nothing happens ‘rotateY’ or ‘rotateX’
The code utilized Hype's API which supports "rotateZ"... but not "X" or "Y". So we need to adjust the code to use a non-API approach the "style transform property":