There seem to be some issues with pointer events functioning properly on mobile devices

I have a code snippet that manages pointer events:

container.on('pointerdown pointerup pointercancel pointerout pointerleave', console.log);

While this code functions correctly on my computer, it behaves differently on mobile. Upon touching the screen, it triggers pointerdown as expected. However, when I move my finger, it quickly triggers pointercancel, pointerout, and pointerleave. Furthermore, lifting my finger does not trigger pointerup.

https://jsfiddle.net/zr8qeo7p/

Answer №1

One reason for browser interference with gestures is to facilitate page scrolling and updates. To counteract this, you can include touch-action: none; in your CSS for the current element before any pointer events occur.

Alternatively, utilizing touch events (instead of pointer events) with passive: false and event.preventDefault() immediately (outside of a promise) can prevent browsers from intercepting gestures after a pointer event occurs. Ensure that this listener is added first in order to take precedence over other event listeners.

const onTouchMove = (ev:TouchEvent)=>{
  ev.preventDefault()
}
element.addEventListener(
  'touchmove',
  onTouchMove, 
  { passive: false }
)

Despite these methods, there may still be issues with the pointerleave event not functioning correctly when moving a finger outside of an element compared to using a mouse.

To address this issue and enable functions such as pointerleave, adjustments can be made within the pointerdown event:

const onPointerDown = function (ev) {
  ev.target.releasePointerCapture(ev.pointerId)
}
element.addEventListener(
  'pointerdown',
  onPointerDown
)

Additionally, CSS offers useful properties like user-select: none; (which prevents selection and is inherited) and pointer-events: none; (which renders an element transparent to pointer events and is also inherited).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transferring Data Straight to Google Cloud Storage

I need to download a PDF document in arraybuffer format from a third-party vendor and then directly upload it to Google Storage without saving a local copy of the file. const axios = require('axios'); const google_storage = new Storage({ keyFilen ...

Using VB.NET with Selenium to locate and interact with dropdown elements

My knowledge of selenium is limited, and I'm facing difficulty in selecting an element from a dropdown menu on AliExpress using vb.net. The issue arises when the driver either fails to locate the intended element or finds another element with the same ...

I'm having some trouble with this search filter in Vue 2 - is it failing to display the items as expected

After struggling with this issue for over a week, I've hit a roadblock and need some assistance. I'm currently working on implementing a search filter in Vue 2 with Vuetify, but something isn't quite right. Here's a snippet of the sea ...

Determine if there is at least one element that is true in the array

I am currently working on developing a menu that can detect the active page based on the site's structure, which is purely PHP/HTML without any CMS. While I have successfully implemented navigation for primary links, I am facing issues with the dropd ...

Displaying content in a hidden div on click event

I am part of a volunteer group for prostate cancer awareness and support, and our website features multiple YouTube videos that are embedded. However, the page has been experiencing slow loading times due to the number of videos, despite them being hidden ...

Enhancing the performance of your code by optimizing it using jQuery when a checkbox is either checked or

Looking for ways to optimize a jquery function that toggles a URL parameter based on checkbox status. Any suggestions on how to streamline this code? $('#mapControl').live('click', function(){ var thisUrl = $(location).attr(' ...

What kinds of scenarios call for using Aria-Expanded even when Aria-Controls is not present?

I am curious about the potential use cases for utilizing the aria-expanded attribute independently of aria-controls. Is it possible to indicate a change in state for a node, such as a button, simply by using this attribute? Can aria-expanded be used solel ...

Disappear button once all elements have been added to the array - utilizing redux

I currently have a list of locations with the option to add them all to another array using an 'ADD all button'. The adding functionality works perfectly, but I now need to hide the 'ADD all button' after it has been clicked. So far, I ...

Currently experimenting with jQuery in conjunction with the reddit API to generate individual divs for every post

Issue with displaying post titles, URLs, and permalinks separately. Need them to display together for each post. See the code below: $(document).ready(function() { $.getJSON( "http://www.reddit.com/r/pics.json?jsonp=?", function foo(data) { ...

Leveraging window environment variables for displaying or hiding a React component

Is it a viable option to display or hide a React component using window.env? For instance, imagine we have a feature that is not yet ready for release, and we are considering hiding it by setting window.env.FEATURE_ENABLED=0 (these variables will be fetch ...

Assign values to a nested FormGroup in Angular 10 based on the provided JSON object

What is the most efficient way to set values for a JSON object coming from the backend? I am familiar with manually setting values based on the key param, but are there any other optimized approaches I should consider? //backend response "response": { ...

Bootstrap4 is failing to adapt to mobile devices, and this is not due to a viewport problem

When I view my webpage on a mobile device, it appears in a zoomed-out desktop view instead of the responsive design I see on my computer. I want it to look the same on all devices. The header of my webpage includes this code: <meta name="viewport& ...

Adjusting the values within an ng-repeat directive

I am relatively new to working with angularjs and I am currently trying to modify the data in $scope.works. I have attempted using xeditable without much success. I understand that it is a simple task, but any guidance you can provide would be greatly appr ...

ways to incorporate audio into a hyperlink

Hello everyone, I am looking to incorporate a sound into my link. Can anyone suggest a jquery or javascript method to achieve this? I tried the following code but it didn't work: <div align="center"><a href="our_product.html" class="footerm ...

Put a variable within the echo statement

I want to include a PHP variable in the href attribute of a link within an echo statement. I'm having trouble inserting $myimage after a href="billing/", as it is not displaying anything. Here's my code snippet. $myimage = $row['image' ...

Setting default values for JSON objects by analyzing the data of other objects within the array

I've been grappling with this issue for about 6 days now, so please bear with me if my explanation is a bit convoluted. I'm using NVD3 to showcase graphs based on data retrieved from BigQuery. While the data and graph setup are correct, the probl ...

React - Unable to perform 'removeChild' on 'Node' object: The specified node cannot be removed as it is not a child of this node

I am encountering an issue in my React project with the following structure: <div className="App"> <BrowserRouter> <BasicLayout title={"test"}> <Routes> <Route path="/home&qu ...

What steps can be taken to remove the search parameter responsible for the error?

Imagine having a webpage that displays search results based on the parameters in the URL, like this: https://www.someurl.com/categories/somecategory?brands=brand1,brand2,brand3 This URL will show listings for only brand1, brand2, and brand3. Additionally ...

Can you explain the process that takes place when require("http").Server() is called with an Express application passed in as a parameter?

As I was exploring the Socket.io Chat Demo found at this link: http://socket.io/get-started/chat/, I came across their require statements which left me feeling confused. var app = require('express')(); var http = require('http').Server ...

Discover the magic of AngularJs autocomplete with a focus on exploring

I am currently utilizing autocomplete feature in my AngularJS application using NgAutocomplete module from . I would like to retrieve the continent of the selected city, but I'm not sure how to achieve this. Upon making a request, I receive a response ...