Timing animations with JS setInterval

I want to move objects smoothly in the presentation. For instance, I got a shape_3 on left = 1015. On click I run the following code:

let InterID = setInterval (function(){
prez.object(‘Shape_3’).left(prez.object(‘Shape_3’).left() - 2);
if (prez.object(‘Shape_3’).left()<= 15){
clearInterval(InterID);
};
}, 2);

As I see it: it should take 500 steps to get Shape_3 from 1015 to 15. With the interval set at 2 msec’s the whole process should run in 1 second. It’s more like 10 seconds.

Am I missing something?

Thanks, Rolf

Hi Rolf,

Kindly take a look at the JavaScript code in the attached sample for more information.

Regards,
Untitled7_M.approj (284 KB)

1 Like