animate with requestanimationframe to have a smoother transition in speeds