I appreciate you explaining your question to me in greater detail! I believe I can properly answer the question now. I appreciate your patience.
So, what you seem to be referring to when you say "refresh" is that, in the video, a small GIF appears in the upper right of the screen and a ball can be seen moving downward and then suddenly snapping back into its starting position and repeating the fall. If this is what you're looking to replicate, then this answer should help.
Your code is exactly as it should be. The small demo you see play in the tutorial is, in fact, your exact code. It functions exactly as yours currently does. The reason you see the ball "refresh" in the video is because the creator of the tutorial edited it to repeat, so when the small preview ended, it reset. This made it appear as if the ball was resetting, when really it was just the video. (You can see that the browser window in the preview that the refresh button changes in appearance without being clicked, and the guy's cursor teleports as well. This is what lead me to believe the video was cut.)
I really hope this helps...
Below you can find my previous answer before OP explained exactly what she needed. (There was a misunderstanding on both of our parts.)
Okay I think I have a few things to say here:
- The
setInterval()
function takes two parameters. A function, and an "interval timer" which is in milliseconds. Now, whatever code is inside the function passed will be run every time x amount of milliseconds passed. Take this example:
setInterval(() => {console.log("something")},15);
"something" will be logged to the console every 15 milliseconds.
Okay, now that we have that out of the way, I see you say in one of your comments above that "The tutorial followed suggested that the "10" was the refresh rate, but I think it is not. That 10 somehow makes the ball move slower or faster in a downward motion."
10 is the refresh rate. 10 is the amount of milliseconds that are allowed to pass between calls to the function that "moves the player in a downward motion", and the lower the number 10 is, the faster the player will move down since the code that makes the player move down is being executed more frequently... So this makes perfect sense.
Now, the second thing I want to say is this: Why make a game using HTML elements manipulated by CSS through JavaScript instead of just making a game using the HTML <canvas>
element? Manipulating the CSS of DOM elements tends to be unreliable in the game development realm, and it's also slower (since the engine has to continually re-calculate the "flow" of the page) and more complex... There's no benefit to it at all. (It uses more code, it runs more inefficiently, it's less readable, it's less reliable, etc)
So why don't you simply use the <canvas>
tag and manipulate it using the 2D context or using a library like p5.js or something similar? Is there any particular reason you're doing it the way you're doing it?