Refactored swipe bar code to use requestAnimationFrame