Disable vertical scrolling while carousel is being horizontally scrolled

I'm currently developing a Vue.js application that includes three horizontal-scrolling carousels on one of the pages. However, I am having an issue with unwanted vertical scrolling while the user is navigating horizontally. This causes the layout to move slightly up and down, which disrupts the user experience.

Although I have found a way to disable vertical scrolling (and all scrolling functionality), it requires the user to touch outside the carousel in order to scroll up or down. This results in a less than ideal user experience.

This is the approach I am currently using:

// Method for handling scroll
const touchMoveHandler = event => {
  if(event.cancelable) event.preventDefault();
}

// Get all the carousels
let carousels = document.querySelectorAll('.v-scroller');

// Handle scrolling
for (const carousel of carousels) {

  // Add event listener on touchstart to remove scrolling functionality
  carousel.addEventListener('touchstart', event => {
    window.addEventListener('touchmove', touchMoveHandler(event), {passive: false});
  });

  // Remove previous event listener on touchend
  carousel.addEventListener('touchend', event => {
    window.removeEventListener('touchmove', touchMoveHandler(event));
  });
}

Websites like twich.tv/netflix have carousels that prevent vertical scrolling once horizontal scrolling has begun. However, users can still vertically scroll by touching the carousel and swiping in that direction.

If anyone has insights on how this functionality is implemented, I would greatly appreciate any help or suggestions. Thank you in advance.

Answer №1

When it comes to touch interactions, consider utilizing the css attribute touch-action :

touch-action: pan-x

By setting this property, only horizontal scrolling will be permitted.

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

Tips for inserting a rotated image using CSS

I've created the following code snippet. However, there is a new requirement stating that the image needs to be rotated by 180 degrees. How can I make this happen? #cell { background-image: url("../images/logo.PNG"); background-attachment: fixed; b ...

Discover the secrets of monitoring a class method with node-jasmine

My current setup includes a User module structured as follows: module.exports = User = (function() { function User(params) { this.id = params.id; this.first_name = params.first_name || ''; this.last_name = par ...

Use Javascript's JQuery library to apply functionality to a newly inserted and cloned

I am facing an issue while trying to implement JQueryUI's DatePicker on a node. It works perfectly fine for all the existing nodes, but when I use the clone function to add new nodes, it doesn't seem to apply as expected. Here is the function th ...

Experiencing challenges working with the offset class in Bootstrap 4

Recently, I attempted to use offset in my form rows and columns to center them using Bootstrap 4 documentation. Unfortunately, it didn't work as intended and now I'm stuck trying to figure out the problem. Despite looking for similar issues onlin ...

The function req.flash does not exist in Express Passport

I am currently working on user authentication using passport and trying to implement flash messages. I have set up the local strategy in passport-config.js, but when running the code, I encounter an error stating "req.flash is not a function" in the passpo ...

Issue with MongoDB: Using $unset with an empty parameter results in a 409 error

When updating values dynamically, I often need to set or unset them. However, there are times when I only need to do one or the other. Here is my current approach: Collection.update( { _id: id }, { $set: data, $unset: remove ...

Using inline SVG in a Vite production build

When utilizing Vite and Vue, my goal is to compile a single JavaScript file without creating an assets directory that includes SVG and GIF files during the build process. I want to achieve this without manually inserting the SVG code in a Vue JS file as a ...

Is it feasible to send an AJAX POST request to a server with a distinct domain while utilizing basic authentication?

I have encountered an issue while attempting to send a POST request to a server with a different domain that necessitates basic authentication. Despite my best efforts in experimenting with beforeSend and withCredentials, the basic auth headers do not get ...

Is it possible for two different forms to invoke a single Javascript function?

I have a page with two separate formulas. Each formula has its own form with inputs, and both forms call the same Javascript function on key up. However, only the first formula seems to be working. I suspect that changing the structure of the JS file may ...

It never fails to function automatically, no matter which script is being executed

By default, the script will always be executed regardless of its environment. Check out my code snippet: import { Pool } from 'pg'; import config from './../config'; const connectionString = () => { switch (process.env.NODE_EN ...

Enhancing Sales Orders in NetSuite by Integrating Drop Ship Purchase Orders

Currently, I am faced with the task of generating drop ship purchase orders against existing sales orders in NetSuite that already have one or more drop ship POs associated with them. While typically this can be easily accomplished through the user interfa ...

The title must not include the phrase "Automated transfer from npm to vue application."

Utilizing npm to download JavaScript libraries is convenient, although integrating them into a Vue app can be quite challenging. I am unsure if there is an established method for this, as various approaches are found online. Sometimes these libraries are ...

Hide the menu when it is clicked in a React component

My objective: Implementing a functionality to close the Navbar by clicking the button placed within it. Despite my efforts, I am unable to make it work. I would appreciate any guidance on what I might be missing! Below is the code for my Navbar: import R ...

HTML content for Bootstrap 5 popover

I've been utilizing Bootstrap 5 popover, but it doesn't seem to display the HTML content I need. I came across a solution on this particular thread: How can I include an html tag attribute in bootstrap 5 popover setAttribute()? It worked well ...

The function `req.send` is not a valid function in NODE - TypeError

I can't figure out what the issue is. I keep getting an error that says TypeError: req.send is not a function const express = require("express"); const app = express(); const courses = [ { id: 1, name: "courses2" }, { id: 2, name: "courses2" }, ...

The positioning of CSS arrows using the "top" attribute is not relative to the top of the page when using absolute values

I am currently working on positioning the arrow in the screenshot using TypeScript calculations. However, I am facing an issue where the position is being determined based on the top of the black popup instead of the top of the screen. From the top of the ...

The Vue.js reactivity system does not detect changes when a property is updated within a WebRTC callback

Is Vue.js component creation becoming a challenge for you? Imagine creating a small component that requires permissions for the camera and microphone from the user, displaying that stream on a canvas. Sounds simple, right? However, let's face reality ...

Contrasting the syntax differences between "new require('underscore')" and "require('underscore')" in NodeJS with Webstorm 7 autocomplete capabilities

Within certain app.js files, the code below is utilized: var _ = require('underscore'); _.times(2, function() { console.log('Hello'); }); There was an issue in Webstorm 7 regarding the unresolved function 'times'. After s ...

Trouble with MongoDB's collection.find() function in an Express application JavaScript file

Recently, I've delved into backend development with node.js and express.js, as I work on creating a website and a Shopify app using MongoDB for the database. Both the website and the Shopify app need to access the same database, which I've named ...

Is there a way for me to extract a smaller segment from an ID label?

I am working on a web development project and I have a set of buttons within a specific section. Each button has an id in the format of #balls-left-n, where n ranges from 1 to 15. My goal is that when a user clicks on one of these buttons, I want to extra ...