Disable vertical touchmove events to prevent scrolling vertically, while still allowing for horizontal touch and the use of buttons for scrolling

I am working on an iPad app that includes a jQuery widget with both horizontal and vertical scrolling functionality. I want to disable vertical scrolling via touch events while still allowing users to scroll vertically using buttons (such as a slider).

Is there a way to prevent vertical touch scrolling but retain horizontal touch scrolling? Any suggestions?

Answer №1

mainContainer.on('touchmove', function(e) {

    var xStart, yStart = 0;

    xStart = e.touches[0].screenX;
    yStart = e.touches[0].screenY;

    var xMovement = Math.abs(e.touches[0].screenX - xStart);
    var yMovement = Math.abs(e.touches[0].screenY - yStart);
    if (friendsList.has($(e.target)).length
        || msgContainer.has($(e.target)).length) {

        if ((yMovement * 3) > xMovement) {
            e.preventDefault();
        }

    }

});

This particular script is programmed to prevent vertical scrolling when a user engages in touch movement on the screen, while still allowing horizontal scrolling.

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

Challenges with hover effects in Vue JS

When hovering over one of two images, a specific component is displayed. Hovering over the first image reveals a component with a red background, while hovering over the second image reveals a component with a yellow background. My actual code differs gre ...

Utilizing window.location.pathname in Next.js for precise targeting

Are you familiar with targeting window.location.pathname in NEXT.JS? I encountered a red error while using this code in Next.js const path = window.location.pathname console.log(path) // I am able to retrieve the pathname here Then { ...

"Enhancing User Experience on iPad: Avoiding Input Focus Disturbances Following an

I've been searching everywhere but can't quite find the right solution to my problem. In a nutshell, I have a web app designed for the iPad that is functioning properly. However, there is an Ajax form on the app that submits correctly as well. T ...

Is there a way to make my item reach a height of 100%?

I've created a unique Wordpress theme and I'm looking to make an element 100% height to fill the remaining available space. Here is the HTML code snippet: <header id="masthead" class="navbar navbar-default" role="banner" style=" backgrou ...

Is there a way to remove information with react and axios?

While working on a project, I encountered an issue with using .map() to create a list. When I console log the user._id on my backend, it displays all the ids instead of just the one I want to use for deleting individual posts by clicking a button. Each pos ...

Get rid of unsafe-eval in the CSP header

I am facing an issue with my old JavaScript code as it is using unsafe-eval. The client has requested to remove unsafe-eval, but the code relies on the eval method in all JavaScript libraries. Removing unsafe-eval breaks the functionality of the code. How ...

Implement localized strings within the interface builder by using the storyboard

As a newcomer to iOS development, I've been contemplating whether it's feasible to directly utilize localized strings from my "Localizable.strings" file in the storyboard. Unlike Android, where you can easily reference strings from an XML file li ...

Creating a text-only fadein/fadeout carousel using JavaScript with a similar functionality to Bootstrap

Is there a way to create a fade-in/fade-out text only carousel similar to the one on the header of this website using just a few lines of CSS and Javascript instead of including the whole Bootstrap framework? I examined the code of the website and it appe ...

Display notification only on certain days

I'm trying to create an alert that only pops up on specific days, but I can't seem to figure it out $(document).ready(function () { $days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday&a ...

What is the best method for sending JSON data to an ASP Server through AJAX?

I'm currently working on a website built with ASP.NET that requires data retrieval from CloudKit. Utilizing CloudKit JS, I successfully retrieve a record from CloudKit and aim to send the data to the server using C# in my JavaScript code. I can conver ...

Can you identify this pattern: .on('eventName', function(){...});?

Do you recognize the .on('eventName', function(){...}); pattern commonly used in jQuery, socket.io, peerjs, and other libraries for event handling? What is this pattern formally called? I am interested in understanding the underlying structure, ...

Code-based document editing with CouchBase

To test Couchbase, I need to create a servlet that will edit 1,000 JSON documents by changing the value of '"flag": false' to '"flag": true'. How can I achieve this task? Here is my view code for finding documents with '"flag": fa ...

Unfinished card or cut-off content within a bootstrap accordion

Greetings to the StackOverflow community! I am facing an issue with my accordion and card setup, where the card is not fully displayed within the button at the bottom. The following image illustrates the problem: https://i.sstatic.net/aSFsc.png Here is ...

Next.js throws a ReferenceError when the self variable is not defined while creating a child process using a custom webpack configuration

Trying to create a child process in Next.js for a time-consuming operation. Here is the webpack configuration (next.config.js): const { merge } = require('webpack-merge'); module.exports = { webpack: (config, { buildId, dev, isServer, defaultL ...

Unable to include Title as a parameter in Jquery message box

Below is the HTML code I have written: <div id="dialog" title=""> <form action="" method="post"> <label>Name:</label> <input id="name" name="name" type="text"> </form> </div> This is my ca ...

Having trouble getting the npm package with @emotion/react and vite to function properly

Encountering an issue with the npm package dependencies after publishing, specifically with @emotion/react. This problem arose while using vite for packaging. Upon installing the package in another project, the css property appears as css="[object Ob ...

Leveraging webpack for requiring modules in the browser

I've been attempting to utilize require('modules') in the browser with webpack for the past couple of days, but I could achieve the same functionality with browserify in just 5 minutes... Below is my custom webpack.config.js file: var webp ...

Customizing the title style of the Material-UI app bar

Is there a way to customize the AppBar title in Material-UI without using inline styling? I have a separate CSS file and I want to be able to adjust the size of the title, for example. Something along these lines: .app-bar title { font-size: 120px !i ...

Utilizing node.js modules in .html via importing

I am currently developing a sophisticated program that involves uploading an excel sheet, creating a table, and then manipulating the data within the table. My task includes reading the first column of all rows and making an API call to the server for eac ...

Modify the Link's Color

How can I change the color of a link inside a DIV? The current code isn't working for me. <style type="text/css"> .someDiv { font-size:14px; color:#c62e16; } </style> <div id="someDiv"> <a href="http://www.s ...