Added swipe and changed to requestAnimationFrame to prevent flickering