Forum Discussion
Rotating a shape 90° shouldn't be too complicated but...
- 2 years ago
Hi ThierryEMMANUEL I have the solution for me, but let me know if you need any tweaks to it. This leverages the GSAP library as it is the cleanest solution. In the attached video, I explain the code, and also talk through some modifications you could make. This method also uses some Storyline variables, which may help configure the functionality from Storyline so it is a bit easier to work with for none programmers.
I'll have a Pietra please. ChatGPT reckons it's one of the most expensive in France ;)
Working file attached:
Wow! Shorter seems harder, and it works perfectly VicovandenEv121 In that case, I'd be happy to buy you a beer too. There's just one little problem: if you click again before the end of the rotation (1s), the angle less than 90° is added to the next and the rectangle is shifted (minus 180°, minus 270°, minus 360°, etc). I think there's a solution to this problem in Sam's code, with the line let rotationdegree = 0. I'll try to fix this problem tomorrow morning. But any ideas are welcome. Many many thanks. For me, it's late and time for a drink.
Hi VicovandenEv121 . The beauty of this code is its small size. I thought I had solved the problem of preventing the rotation from starting from an intermediate position when the user clicks again before the animation is finished, by creating a variable (rotationDegree) stored in the window object, which allows it to persist between executions without resetting. Actually, chapGPT did it. Here is the modified code:
window.rotationDegree = (window.rotationDegree || 0) - 90;
let object1 = document.querySelector("[data-model-id='6nmK88deM2z']");
gsap.to(object1, { rotation: window.rotationDegree, duration: 1 });
It works for the first object! But since I want to target multiple objects, the objects share the same rotationDegree variable in their code and their first rotations are at first heretical. I guess it is normal. I'm still looking. (This is the last time I'll ask you if you don't have time. You've already earned your beer anyway.)
- VicovandenEv1212 years agoCommunity Member
Hi ThierryEMMANUEL I'll have the Trappist Westvleteren 12 🍺
- ThierryEMMANUEL2 years agoCommunity Member
Is this your country? VicovandenEv121
One of the 12 Trappist beers in the world, you're a connoisseur. Looks like we're talking more about beer than Javascript in this thread.😀- VicovandenEv1212 years agoCommunity Member
I live in the Netherlands, but love special beers. And Belgian beers are amongst the best in the world ;-)
Related Content
- 2 years ago
- 7 months ago
- 2 years ago
- 2 years ago
- 2 years ago