+ 1

Add eventlistener last jump1 function not runing ?

I want to make a jump button ,when i will click jump button, It going to up and come to down. My code is here : Which is not working https://code.sololearn.com/WGh1CEsi4Du3/?ref=app

23rd Jan 2021, 7:14 AM
Sajid Ali
Sajid Ali - avatar
5 Antworten
+ 1
Add a class with jump animation .jump { animation: jump 1s cubic-bezier(0.25, 0.1, 0.25, 1) 0s 1; } @keyframes jump { 50% { bottom: 450px; } } Then add the jump class when onClick event triggered, with timeout to remove jump class later. https://code.sololearn.com/Wp07RUDhWJ8K/?ref=app
23rd Jan 2021, 7:49 AM
Calviղ
Calviղ - avatar
+ 3
Sajid Ali cubic-bezier is defined in your code, I just copied from your code.
23rd Jan 2021, 8:03 AM
Calviղ
Calviղ - avatar
+ 2
Your code jump on 450px and just back to 350px. For this reason the interpretation of this code is so that the 450px will be overwritten with 350 px. The position stay the same.
23rd Jan 2021, 7:48 AM
JaScript
JaScript - avatar
+ 2
The easier solution on basis of your code will be differenting the time points of this two positions, for example with code as follows: oh.addEventListener("click", jump = ()=> { ob.style.bottom = "450px"; setTimeout(() => { if(ob.style.bottom >= "440px") ob.style.bottom = "350px"; },400) } https://code.sololearn.com/WHW56E8AKMvI/?ref=app
23rd Jan 2021, 8:03 AM
JaScript
JaScript - avatar
0
Calviղ can you explain ? What is cubic bez... ?
23rd Jan 2021, 7:58 AM
Sajid Ali
Sajid Ali - avatar