This article mainly introduces how to implement the buffer motion effect in javascript. it involves techniques related to element motion operations in javascript and has some reference value, for more information about how to buffer the motion of JavaScript code, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
The instance can be quickly started and then slowed down until it is stopped.
Key points:
var speed = (target-box.offsetLeft)/8;
The value of the target point minus the current position of the element is divided by 8, because the value of offsetleft keeps increasing, so the speed value also keeps decreasing.
speed = speed>0?Math.ceil(speed):Math.floor(speed);
Positive speed is rounded up, reverse speed is rounded down
Code:
Untitled DocumentScript
Script
I hope this article will help you design javascript programs.