0

How do you add multiple transformations to a single element via javascript?

I want the pancake to move 20vh up and then 20vh down but I can only get one transformation to work. How do I add more? window.onload = function() { document.getElementById("pancake").addEventListener("click", flip); function flip() { document.getElementById("pancake").style.transform = "translate(0px, -20vh) translate(0px, 20vh)"; document.getElementById("pancake").style.transition = "transform 2s"; } }

1st Mar 2021, 1:29 AM
tori the crafter 💛
tori the crafter 💛 - avatar
9 Respostas
+ 3
visph shorter than that... @keyframes anim { from,50%,to { transform:translate(0,0); } 25% { transform:translate(0,-20vh); } 75% { transform:translate(0,20vh); } } https://code.sololearn.com/WRgSW35g3Aa8/?ref=app as for what Mirielle[ INACTIVE ] suggested, with sin... https://code.sololearn.com/WZg12VAUH01a/?ref=app
1st Mar 2021, 5:25 PM
Nor'wester đŸŒȘ đŸ‡§đŸ‡© (INACTIVE)
Nor'wester đŸŒȘ đŸ‡§đŸ‡© (INACTIVE) - avatar
+ 1
Mirielle[ INACTIVE ] not as long as you seems think: @keyframes anim { from { transform:translate(0,0); } 25% { transform:translate(0,-20vh); } 50% { transform:translate(0,0); } 75% { transform:translate(0,20vh); } to { transform:translate(0,0); } } and then set 'animation-iteration-count' to 'infinite' to get infinite up/down mouvement...
1st Mar 2021, 3:13 PM
visph
visph - avatar
+ 1
Mirielle[ INACTIVE ] visph thank you guys for the explanation! i’m going to practice it in my next code 👍👍
2nd Mar 2021, 2:20 AM
tori the crafter 💛
tori the crafter 💛 - avatar
2nd Mar 2021, 2:29 AM
tori the crafter 💛
tori the crafter 💛 - avatar
0
Mirielle[ INACTIVE ] what's the relation between OP question and sin(x), as OP ask just for transform? I agree with you that you could do smoother animation using it, but actually, OP question is about chaining animations by just setting css once... not handling full animation frames by js ^^ however, by using the animation/transition-time-function you could set such close behavior... one thing at a time, didn't you think? ;) by the way,
1st Mar 2021, 7:54 AM
visph
visph - avatar