Answer the question
In order to leave comments, you need to log in
How to move a block in jquery so that when clicked multiple times it linearly accelerates?
Let's say there is a block of 20x20 pixels and a button to move to the left. With a simple view like:
$("#button").click(function(){
$("#block").animate({ left: "+=20" }, 1000);
})
Answer the question
In order to leave comments, you need to log in
Give the animation to css, this is how you can do
codepen.io/iiil/pen/ahIxC
In theory, you can still make an adjustment for the time between clicks, then there will be no jerks. Take the time of the click, compare it with the time of the previous click (starting from the second one) and subtract this time from the animation time.
Stop the current animation $("#foo").stop()
And start the animation again at the new speed.
You can stop the previous operation (.stop()) and start a new, faster one.
You can also move the block wrapper with the next click, then the total speed of the main block will be greater.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question