Is there a way to determine if scroll events are triggered just once, similar to how they are on touch devices?

When it comes to iOS devices (and possibly Android ones), the scrolling behavior is quite different. The scroll event is triggered only once after the entire scroll process has been completed.

Is there a way for me to determine if the browser follows this specific behavior?

I've considered using window.Touch or Modernizr.touch, but they do not provide any insight into the scrolling behavior. It's like trying to determine if someone likes croissants just by knowing they are French, isn't it? :)

Answer №1

I believe your assessment on detection is accurate because various devices have different capabilities when it comes to touch and mouse interactions. Some devices, like Windows 8 tablets, support both touch and mouse behaviors, while others, such as phones, only support touch, and desktops may only support mouse. This diversity makes it challenging to definitively categorize a device based on behavior since some devices could possibly have both touch and mouse capabilities.

If your goal is to determine whether to respond immediately to every scroll event or introduce a short delay to analyze the scroll destination, you can implement a hybrid solution that caters to both scenarios.

var lastScroll = new Date();
var scrollTimer;
window.onscroll = function(e) {

    function doScroll(e) {
        // insert your scroll logic here
    }

    if (scrollTimer) {
        clearTimeout(scrollTimer);
        scrollTimer = null;
    }

    var now = new Date();
    
    if (now - lastScroll < 500){
        scrollTimer = setTimeout(function() {
            scrollTimer = null;
            doScroll(e);
        }, 1000);
    } else {
        doScroll(e);
    }
    lastScroll = now;
};

doScroll() represents your scroll processing algorithm.

This method combines elements of immediate response and delayed reaction. It triggers an action upon the first scroll event received after a period of no recent activity. In a scenario where multiple scroll events occur consecutively, it responds to the initial event and waits for a brief pause before proceeding further.

You might need to adjust two specific time thresholds. The first parameter dictates how closely spaced scroll events should be considered rapid succession from a single user action (currently set at 500ms). The second parameter controls the duration of inactivity required to process the current scroll position under the assumption that the user has stopped moving the scrollbar (currently set to 1s).

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

Is there a way to modify the CSS display property upon clicking a link or button?

I have a ul with the id of "menu-list". The display property is set to "none" in my CSS file, but I want it to switch to "flex" when a link is clicked. I am trying to use the click event on the link to change the display prop ...

Are there any available proxy server or Apache modules for converting XML SOAP responses to JSON format upon installation?

Lately, I have been trying to connect to a remote web service using Ajax, but I realized that the service (FedEx Services API) does not seem to support JSON responses. Is there a proxy server or an Apache solution that can help convert the XML/SOAP respo ...

What is the process for verifying an email address using the deep-email-validator package from npm?

I'm looking to verify the existence of an email address used for registration on my website, ensuring it's not just a temporary one. How can I achieve this utilizing the npm deep-email-validator package? Within my HTML page, I've assigned n ...

Using Capybara for testing integration with asynchronous JavaScript

I am currently facing an issue with a failing Rails integration test that has me stumped. The test utilizes Capybara with Selenium as the driver. The specific problem lies in verifying that certain page content is removed after an AJAX call is made. Essen ...

Steps for filtering a table with Vue and Element-UI

I am currently working with Vue and Element UI, and I have a requirement to display only elements in my table that have a status of 0. To retrieve my data, I am using Express and Axios. The code for this looks like: axios.get('http://127.0.0.1:8000/ ...

Retrieving the chosen value when there is a change in the select tag

Building a shop and almost done, but struggling with allowing customers to change product quantities in the cart and update prices dynamically. I've created a select-tag with 10 options for choosing quantities. I'd like users to be able to click ...

Executing processes individually within AngularJS

Just making sure I understand correctly, I have a simple web service resource query function set up like this //Get country lists $scope.getCountry = function(){ $http({ method : 'GET', url : cdnLinks('country&apos ...

Managing data from two tables in Node.js with ejs

I have a question regarding my node.js project that I need help with. As a beginner in this field, I believe the answer may be simpler than anticipated. In my code file named index.js, I found the following snippet after referring to some online documenta ...

Inject javascript variables into a {% static "..." %} path declaration

I am currently working on creating an array for my server that will preload images with specific paths: var i = 0; while (face_cursor < faces_gone_through.length) { for(j=0; j<=100; j+=10) { load_images_array.push('{% static "/i ...

Launch the file explorer using JavaScript/HTML

Is there a way to launch a real explorer window instead of the browser's directory look? For example, like the windows key + e window... Is there a method using html or JavaScript? I've noticed it in a Firefox add-on called new tab king, but I c ...

Issues with Bootstrap 4 (possibly JQuery) - mobile menu navigation items are unresponsive

I've encountered an issue with my Bootstrap4 navbar on mobile screens where the links in the menu don't seem to work. Below is the code I used: <nav class="navbar navbar-expand-sm navbar-dark" style="background-color: #E2BA28"> < ...

Is it possible to target elements within a UMAP iframe using CSS?

I have integrated a uMap map into my website. Here is the code: <iframe id="umapiframe" class="iframe-umap" width="100%" height="300px" frameborder="0" allowfullscreen src="//umap.openstreetmap.fr/f ...

Is there any method to avoid the hassle of constantly adjusting margins and paddings on my one-page website?

One issue I encountered was that the buttons weren't scrolling me to the top of the anchor, instead scrolling too far into the section due to the fixed navbar overlapping. I tried solving it with margins and paddings but believe there must be a simpl ...

Uncontrolled discord bot flooding with messages despite being set to send messages only once every 60 seconds

const Discord = require('discord.js'); const { Client, MessageAttachment } = require('discord.js'); const client = new Discord.Client(); client.once('ready', () => { console.log("Ready!") }) client.on(&apos ...

I am unable to send back my JSON object

I seem to be having trouble returning a JSON object as all I get is an undefined variable. The code below is supposed to fetch a JSON element from an API. It appears to work within the success: function, but when attempting to use that data elsewhere, it ...

Is there a way to convert a Blob object to a JSON object in Javascript?

let dataFile = new Blob([response.data], {type: 'application/json'}); Within the response.data is a JSON file. My goal is to extract the contents of this file and set them as a JSON string to a variable in JavaScript. I've experimented wit ...

Using AJAX and Spring MVC to render JSON objects in bracket notation within a POST request

Why is a JSON rendered in bracket notation when bound to a Web Request? I am working on an application that involves making 2 consecutive REST Controller calls. The first call reads an address from a form, serializes it, sends it via AJAX to a validation ...

Effortless method to handle package.json configurations

Is there a better approach for seamlessly transitioning between using npm link and git, or another solution that caters well to both front end and back end developers? The dilemma I'm facing revolves around developing a website that utilizes multiple ...

Locating the source and reason behind the [object ErrorEvent] being triggered

I'm facing an issue where one of my tests is failing and the log is not providing any useful information, apart from indicating which test failed... LoginComponent should display username & password error message and not call login when passed no ...

Transform Dynamic Array to JSON structure

I am currently developing a feature in my SvelteKit application that allows users to create custom roles for themselves. Users can input a role name and add it to an array, which is then displayed below. https://i.stack.imgur.com/oUPFU.png My goal is to ...