Transform vertical and horizontal scrolling actions into solely horizontal scrolling using HTML and JS

I'm currently working on a unique React.js website that features a horizontal-scrolling portfolio. The website functions as a visual gallery, allowing users to easily scroll through images using their trackpad.

Within the website, I have set up a large container with the following styling:

  overflow-x: scroll;
  overflow-y: none;

  -ms-overflow-style: none;
  scrollbar-width: none;

However, I recently realized that this design may not be user-friendly for those using a mouse on a desktop computer, as horizontal scrolling without a scrollbar can be challenging. To address this, I am now working on implementing a scroll conversion feature to facilitate horizontal scrolling for all users.

After exploring different solutions, I attempted to use the following code snippet:

const scroller = document.getElementById('pageContainer');

window.addEventListener('wheel', e => {
   scroller.scrollLeft += e.deltaY;
});

Unfortunately, this implementation caused issues with scrolling, impacting both vertical and horizontal movement. The scrolling appeared jerky and inconsistent, which was not the desired effect.

At this point, I am seeking guidance on the best approach to achieve smooth horizontal scrolling while maintaining functionality for users with different devices. I aim to create a seamless scrolling experience, potentially incorporating a sinusoidal motion for circular scrolling.

EDIT:

While exploring solutions, I came across a codepen that demonstrated the desired scrolling behavior. Although my implementation did not yield the same results, it inspired me to consider tweaking the scroll-behavior: smooth; property in my CSS, as it could potentially impact scrolling behavior.

My current challenge is finding a way to harmonize these modifications and ensure that all scrolling features work cohesively on the website. Any insights or suggestions on achieving this balance would be greatly appreciated.

Answer №1

If you are looking to incorporate horizontal-scrolling into your portfolio website, make sure to include height and width parameters in your div style. Here is an example:

#content {
  height: 100%;
  width: 9000px;
}

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

Ways to resolve the issue of being unable to retrieve data using jQuery

My code is working, but I am facing a little annoying problem that I can't solve on my own. The problem is that I can only retrieve the first record (id) from my data grid, but I can't retrieve the second or any other record id. For example: W ...

Selecting the child checkbox within the parent div using ng-click

Is there a way to trigger the click event of a parent div on its child checkbox in AngularJS? The Checkbox will have the attribute hidden, necessitating the parent div to act as the clickable element. Sample HTML: <body ng-app="checkboxApp"> ...

Using Angular and nativeElement.style: how to alter cursor appearance when clicked and pressed (down state)

I am working with a native elementRef CODE: this.eleRef.nativeElement.style = "_____?????_____" What should go in "???" in order to apply the :active style to the element? (I want to change the cursor style when the mouse is clicked down, not when it is ...

The issue with the CSS combination of :after and :hover:after across different HTML elements

Encountering an issue while attempting to create a rollover effect using CSS :after and :hover pseudo-elements. Check out the clock and facebook icons on the right side by visiting: See below for the CSS code: .icon { background: url('. ...

What is the best way to capture the return value following an async/await function?

Here is a condensed version of the PoC code that highlights the problem/question at hand. createPost() will provide a "post number" in the ret variable, which is only needed for logging purposes. In the current setup, I have to declare ret outside of the ...

Using jquery to reveal a hidden element by smoothly fading it in

Is it possible to display a concealed div while simultaneously creating a fading effect in jQuery? ...

Is there a straightforward way to upload a folder in a ReactJS application?

I am searching for a way to upload a folder in ReactJS. I have a folder with .doc and .docx files in it, and I want the user to be able to upload the entire folder when they click the browse button. I need to prevent the user from selecting individual fi ...

Arrange the div elements in a single horizontal line

Is there a way to align the company logo div next to the name, address, email, and phone number containers? I've attempted using display: inline and float: right, but the logo isn't moving up as desired. Here's the code snippet: http://jsfi ...

Tips on how to seamlessly incorporate a small image file into the background so that it scrolls along with other elements on

I have a CSS code for a small image file (.png) sized 40x40px that I want to use as a background spread all over the body. Initially, I used 'fixed' which worked but the image didn't move with other elements when scrolling. body{ background ...

Unexpected resizing of DIV element in Chrome

Working on my new PHP website, I encountered a strange issue recently. I have a file for the top navbar that is included on every page and it was functioning perfectly fine. However, while creating a register form, I noticed something odd happening. When r ...

When running "npm install," the system is failing to prioritize transitive dependencies with the highest version numbers

I'm currently tackling a project in Node that involves an SDK and a parent project that consumes the SDK. When it comes to Java, Maven or Gradle will automatically pick the transitive dependency with the highest version number. But how does this proce ...

Dimension of images within bootstrap column division

I have a layout with three columns using col-md-4 for a thumbnail design, and then I have another page with col-md-8. In both cases, I need to display an image. Should I use the same image for both layouts or would it be best to have two separate images, e ...

What is the process for placing the error (404) page in the "dist" folder in a nuxt project?

I successfully implemented an error page following the documentation provided. https://nuxtjs.org/docs/2.x/concepts/views#error-page To achieve this, I created an error.vue file in the /layouts directory and assigned a custom layout to it. <template&g ...

Navigating Angular's Resolve Scope Challenges

As a junior developer, I've been diving into Angular.js and exploring the resolve feature of the route provider to preload my Project data from a service before the page loads. Previously, I was fetching the data directly inside the controller. Howeve ...

Automating the selection of a drop down based on a condition in Angular 2: A step-by-step guide

I'm facing an issue with a drop-down menu where no default value is selected. On my homepage, I need to automatically select an option based on query parameters. I've attempted various methods but none have been successful. Below is the code snip ...

What is the best way to assign a jQuery variable to a PHP variable?

After spending some time searching and working on it, I still can't figure out the answer to this straightforward question. Here is the code I have been struggling with. <script> function calculate() { var total = (parseInt($('#stude ...

The complete page gets re-rendered when Nuxt child routes are used

When I attempt to utilize child routes, my goal is to maintain specific data on the page while modifying other content. To illustrate this concept, I have created a straightforward example available at this link. After selecting "cat" and increasing the ...

Personalized AJAX characteristic inside AngularJs Service

Let's consider a very simple scenario: Here is the code snippet: $.ajax({ type: "GET/POST", url: 'http://somewhere.net/', data: data, beforeSend: '', // custom property }).done().fail(); My main goal is to find a ...

Update the path dynamically in Next.js without the need to reload the page

Every time the user clicks on the continue button, a function is triggered. Within that function, I make the following call: push("/signup/page-2", undefined, { shallow: true }); All dynamic routes resembling /signup/[page].js that return <Component / ...

Ways to identify local storage when a user visits the page for the first time using jQuery

As a beginner in the world of local storage in Jquery, I am looking to implement a feature on my Bootstrap 4 accordion. The desired functionality is as follows: If a user is visiting the page for the first time, all accordions should be open by default ...