handle animation through a requestanimationframe