Is it possible to stop fastclick from triggering the "active" state while scrolling?

Utilizing FastClick on a page with oversized links to eliminate the 300ms delay for taps in mobile browsers has been successful. The "highlight" style for the links' :active states is triggering quickly, thanks to FastClick.

However, a challenge arises when using this setup in Mobile Safari - the :active state fires while tapping and swiping to scroll the page. This creates the sensation that scrolling is impossible without accidentally triggering link taps.

Is there a method to prevent the :active state from activating during scrolling?

Answer №1

Have you considered applying the needsclick class to the body tag?

<body class="needsclick">

...

</body>

It's just a suggestion :)

Answer №2

Great question! +1

The issue at hand is unrelated to FastClick, although using FastClick can complicate the solution. Therefore, I will focus on utilizing pure JavaScript and raw Touch Events instead.

When dealing with a mobile touch device, the implementation of the webview differs significantly from that of a desktop web browser due to platform-specific reasons. One crucial feature in this scenario is momentum scrolling within the webview, which is a hardware-accelerated capability. Essentially, when a scrollable area is touched on the screen, the hardware sets a 200 millisecond countdown timer that triggers accelerated scrolling. During this period, touch events are not broadcasted as they pertain to the hardware-accelerated scroll. By utilizing preventDefault on the touch event within the specified timeframe, the timer can be cancelled, and momentum scrolling can be prevented.

Here is my approach to addressing this problem assuming you are employing native scroll (i.e., overflow:scroll). The method involves attaching a touchstart event to the desired element. Once the touchstart event is triggered, additional touchend, touchmove, and touchcancel events are attached to the target. Subsequently, a setTimeout timer is initiated to remove these added events after 140ms.

Below are snippets from my production code:


var eventify = (function () {
    // Function for adding events to elements
})();

var uneventify = (function () {
    // Function for removing events from elements
})();

Additionally, I have a method named tapify specifically for tap events on the scroller:


var tapify = (function () {
    // Function for handling tap events
})();

I utilize global.isIos to differentiate the target device, as Android ceases sending touch events to the webview after 200ms.

To attach the event to an element or a collection of elements, simply use:


tapify(document.querySelectorAll('button'), function (e) {
      // Your event handler logic here!! 
});

I hope this explanation aids you in resolving your issue!

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

Asking only to re-answer incorrectly answered questions in an array using JavaScript prompts and loops. How can this be achieved without asking to repeat the entire loop?

Goals : To require the user to input the displayed words in the designated fields. To validate if the typed words are an exact match to those requested. If correct, proceed to the next word. If incorrect, prompt the user to retype the wrongly entered word ...

Display jpg images while authenticating using nextauth version 4.22.1

Hello everyone, I am currently working on displaying images with authentication using nextauth 4.22.1, as mentioned in the title. I have set up the new /app directory within the /src directory. While it occasionally works, most of the time it does not. H ...

How can I determine the spinning direction using the CSS rotate function?

Take a look at this example: https://jsfiddle.net/s2Lngpto/1/ I'm working on a spinner animation that I want to spin 315 degrees (and complete a full cycle in 8 rotations), but I'm finding CSS behavior to be quite peculiar. When specifying rotat ...

jQuery dynamic id selection

I'm facing a challenge with dynamically generated forms that have dynamically generated IDs and potentially classes. Although the forms are identical, they each have a unique ID at the end. How can I target and manipulate each set of inputs individua ...

What should I verify if the Grails application is not loading on IE9 exclusively?

In the process of developing a Grails project that incorporates some JS code, I encountered an issue where the project ran smoothly on Google Chrome (v34.0.1847.116 m) and Mozilla Firefox (v28.0), but failed to start on IE (v9.0.23), resulting in a blank s ...

Setting the value of a custom component property dynamically after the component has been rendered

I'm currently developing an Angular application and have a specific requirement to work on. I am using a custom component with 3 inputs, and I want to bind this custom component tag in the HTML of my page. <my-column [setInfo]="info" [dis ...

Resolve the issue of text overlapping on an image when zooming in

There seems to be an issue with overlapping text and images when zooming the page. I have included a screenshot for reference, please take a look and provide a solution. Thank you in advance.https://i.sstatic.net/oVlGN.png Here is the CSS code causing the ...

How can I make the Bootstrap tooltip only appear when clicked inside a Vue Component and disappear when hovered over?

I am having a challenge with Bootstrap ToolTip in my Vue component. I only want the notice to show when the button is clicked, not on hover as it currently behaves. I attempted using jQuery within the Vue component without success. Can someone please adv ...

Angular 2: Enhancing User Experience with Pop-up Dialogs

Looking to implement a popup dialog that requests user input and returns the value. The popup component is included in the root component, positioned above the app's router outlet. Within the popup component, there is an open() method that toggles a ...

The image slide change feature ceases to function properly when incorporating two separate functions

I have a function that successfully changes the image of a container every 5 seconds. However, I am facing an issue when trying to add 2 containers side by side and change their images simultaneously. When I run the functions for both containers, only one ...

Notification indicating that an object has been identified

Here is the code I am working with: const username = "john"; const password = "doe"; const url = '//api.bos2.cf/?type=verify&username=' + username + '&password=' + password + '&callback=?'; $.getJSON(url, functi ...

Implementing new updates to an object without affecting existing values in Vue.js 2

I am currently facing an issue with updating values for an object received in a payload before saving it to the database. Despite making changes, the new values are not being persisted correctly. I am utilizing Vue.js 2 for this task. How can I effectively ...

What steps can be taken after the addClass function has been triggered?

I am trying to achieve a functionality where upon clicking a button, a div will add a class that changes its width to 150px. However, I want something to be shown in console.log only after the div has become 150px in width. Can anyone assist me in achievin ...

Add a square div in every direction around the existing content in an HTML file

Begin by locating square number 1. Once you press the + symbol above square 1, square 2 will appear. From there, you can click the + on the right side of square 2 to reveal square 3. Is it possible to achieve this sequence? If so, what is the best way to ...

Troubleshooting: React js Project console.logs are not being displayed in the browser's

When working on my current project, I noticed that any time I try to use console.log in the dev tools, it shows as cleared. Strangely, console.log works fine in my other projects. Does anyone have an idea how to resolve this issue? Here is a screenshot of ...

What is the reason for the vertex shader failing to compile?

Recently diving into the world of WebGl, I decided to experiment with a simple example. Here is how I set up my script: Here's my setup script import testVertexShader from './shaders/test/vertex.glsl' import testFragmentShader from './ ...

Guide on configuring and executing AngularJS Protractor tests using Jenkins

I am encountering an error with the following configuration: ERROR registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match the current platform LINUX 18:17:05.892 INFO ...

Style the CSS exclusively to the expanded menu section

I need help with applying CSS rules to my navbar menu without affecting the collapsed menu. I came across a solution here and tried using this code: @media (min-width: 980px) { /* your conditional CSS*/ } However, the issue arises when my browser win ...

Exploring the Concept of Event Bubbling in ReactJS

Having recently delved into React.js, I've encountered a roadblock that has persisted for the past three days despite my attempts at various solutions. The issue revolves around two functions in my parent component named checkout: handleSeleteAddress ...

Establish a connection between a react-native app and a MongoDB Atlas cluster database

I'm struggling to grasp the concept of connecting my React Native app to the MongoDB Atlas Cluster. Essentially, I want to retrieve user data (username and password) from a login component page and verify its existence within the Atlas Cluster databas ...