Within my JavaScript code, I have a rather simple event listener set up to listen for a click:
element.addeventlistener('click', ()=>{
#do somthing
})
However, I am encountering an issue on IOS (iPhone) where scrolling triggers the event listener when touching the element to start the scroll.
Is there a way to prevent the event listener on iPhone unless there is no scrolling following the click?
Essentially, I want to execute a function if clicked without triggering it when scrolling occurs.
Alternatively, there may be a different solution to explore without relying on a library.
Thank you, W
ANSWER
Despite trying the solution provided below (which did work to some extent), the issue persisted. This prompted me to inspect my CSS code, where I discovered that on IOS mobile devices, the CSS pseudo selector :focus
is activated while scrolling over an item.
To resolve this, I implemented a media query to restrict the use of :focus
to desktop-sized devices and above, effectively resolving the issue.