+ 1

I want the red ball to bounce. Why isn't it working?

https://code.sololearn.com/WTQ64qF5e9SY/?ref=app

2nd Apr 2022, 3:32 PM
Spencer Pawlik
Spencer Pawlik - avatar
15 Réponses
+ 3
Add function definition out side onload but in onload.. edit: function bounce() { //.. } window.onload = () => { bounce() };
2nd Apr 2022, 3:38 PM
Jayakrishna 🇮🇳
+ 3
Lego in Motion Why there is 2 times height, 2 times weight, 2 times bottom in JS section?
2nd Apr 2022, 3:50 PM
A͢J
A͢J - avatar
+ 3
Lego in Motion I modified your animation to use only css animation https://code.sololearn.com/WO86cE4h1iUH/?ref=app
4th Apr 2022, 4:34 AM
Bob_Li
Bob_Li - avatar
+ 2
What did you changed? It just worked but not now? edit: Lego in Motion function working fine. but problem may in setting values.. what are you trying actually? edit: add it in reverse..
2nd Apr 2022, 3:46 PM
Jayakrishna 🇮🇳
+ 2
Add in reverse window.onload = () => { bounce() }; function bounce() { //.. }
2nd Apr 2022, 3:52 PM
Jayakrishna 🇮🇳
+ 2
Try this : window.onload = () => { setInterval(bounce,2000); }; function bounce() { // add your height, width,... setTimeout(down,1000); } function down(){ document.getElementById("ball").style.bottom="0vh"; }
2nd Apr 2022, 4:41 PM
Jayakrishna 🇮🇳
+ 2
Lego in Motion I'm sure there is a simpler way, maybe by using a canvas element, or an physics library. But how about this one? https://code.sololearn.com/Wr2ZuYB8SoZ4/?ref=app Or maybe a css animation? https://code.sololearn.com/W6kQkdeoIUlx/?ref=app I prefer the css animation because it is simpler and you have more choices on the animation timing function. It would take a lot more coding in javascript if you want a non-linear acceleration.
4th Apr 2022, 12:19 AM
Bob_Li
Bob_Li - avatar
+ 1
Still not working. Thanks for trying to help though!
2nd Apr 2022, 3:43 PM
Spencer Pawlik
Spencer Pawlik - avatar
+ 1
Oh I guess I did something different then. Could you change it for me just for a few minutes?
2nd Apr 2022, 3:50 PM
Spencer Pawlik
Spencer Pawlik - avatar
+ 1
I want the ball to bounce up and down for ever. Maybe it won't be so realistic but u can change some stuff later.
2nd Apr 2022, 3:51 PM
Spencer Pawlik
Spencer Pawlik - avatar
+ 1
Nope.😕
2nd Apr 2022, 3:53 PM
Spencer Pawlik
Spencer Pawlik - avatar
+ 1
AJ I want it to go back down later. Is that the problem?
2nd Apr 2022, 3:53 PM
Spencer Pawlik
Spencer Pawlik - avatar
+ 1
Is it in javascript or css? DOM elements or canvas?
3rd Apr 2022, 7:32 AM
Bob_Li
Bob_Li - avatar
+ 1
The link to the code is there. It's javascript.
3rd Apr 2022, 8:30 AM
Spencer Pawlik
Spencer Pawlik - avatar
+ 1
Don't know much about java
4th Apr 2022, 12:56 AM
Terrible Money
Terrible Money - avatar