Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop animation with velocity.js

I'm trying to do that kind of loop animation with velocity.js: translate object on X axis from 0 to 473, then from 0 to 473 and so on.

I've succeeded to do that like this (code below) but on Android Chrome and iOS Chrome browsers the loop starts over with some delay (lag). Can someone help?

function start() {
  $(".el").velocity(
    { 
      translateX: [ -473, 0 ]
    },
    { 
      duration: 8000,
      delay: 0,
      easing: "linear",
      complete: reset
    });
}
function reset() {
    $(".el").css("transform", "translate(0px, 0px)");
    start();
}
start();
like image 448
cesgra Avatar asked May 28 '26 18:05

cesgra


1 Answers

Since you're using forcefeeding, the .css() call is redundant.

Removing that line removes the initial lag on Chrome for Android:

$el = $(".el");
function start() {
  $el.velocity(
    { 
      translateX: [ -473, 0 ]
    },
    { 
      duration: 8000,
      delay: 0,
      easing: "linear",
      complete: start
    });
}

start();

And you can see a live version here.

like image 63
ydaniv Avatar answered May 31 '26 08:05

ydaniv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!