Tips for incorporating Javascript to restrict scrolling to just one:

My HTML page includes a section for filter_options and content. The filter_options contains a list of options. I have set up scrolling functionality where scrolling vertically changes the horizontal scroll position of the options. However, this setup is also affecting the scroll behavior of the content area. How can I make sure that the scroll in the filter_options only works when it is being actively scrolled?

index.html

    document.getElementById("options").addEventListener('mousewheel', function(e) {
        if (e.wheelDelta > 0) {
            this.scrollLeft -= 100;
        } else {
            this.scrollLeft += 100;
        }
    });
body {
    margin: 0;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: white; 
}

::-webkit-scrollbar-thumb {
    background: orange;
    border-radius: 30px;
}

#filter_options {
    width: 80%;
    height: 100%;
    position: fixed;
    top: 0;
    z-index: 2;
    background-color: rgba(66, 60, 60, 0.13);
    float: left;
    overflow: scroll;
}

#filter_options div {
    background-color: rgb(51, 51, 51);
    text-align: center;
    overflow: auto;
    white-space: nowrap;
    margin-top: 5%;
}

#filter_options div div {
    color: white;
    background-color: orange;
    padding: 12px;
    font-size: 20px;
    font-family: "Comic Sans MS", cursive, sans-serif;
    display: inline-block;
    user-select: none;
}

#content {
    height: 5000px;
    width: 90%;
    margin-left: 5%;
    z-index: -1;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>Document</title>
</head>
<body>
   <div id="filter_options">
       <div id="options">
           <div>Option 1</div><div>Option 2</div><div>Option 3</div><div>Option 4</div><div>Option 5</div><div>Option 6</div><div>Option 7</div><div>Option 8</div><div>Option 9</div><div>Option 10</div>
       </div>
   </div>
   <div id="content"></div>
</body>
</html>

Answer №1

Consider using this code snippet:

#content {overflow: hidden}

Answer №2

A brilliant idea just popped into my mind. Including e.preventDefault() prior to the if statement could be the key.

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

What is the best way to showcase an image using Next.js?

I'm having a problem with displaying an image in my main component. The alt attribute is showing up, but the actual image is not appearing on the browser. Can someone please point out what I might be doing wrong? import port from "../public/port. ...

Guide to updating the htmlOutput in shiny with JavaScript

An interactive application showcases a sentence on the screen. Users have the ability to select specific parts of the sentence and apply custom markup by clicking the Mark button. The sentence should then reflect this action in real-time. For example: ...

The issue of undefined return for multiple columns in MVC when using MCAutocomplete Jquery UI

My MVC multiple column is returning undefined. What am I missing or what is wrong with my code? Please help. https://i.sstatic.net/euwe8.png Controller public ActionResult EmployeeIDSearch(string term) { // Get Tags from data ...

Can React-Select be utilized in the browser directly from the CDN?

Is it possible to utilize react-select directly in the browser without using bundlers nowadays? The most recent version that I could find which supports this is 2.1.2: How to import from React-Select CDN with React and Babel? In the past, they provided r ...

How can the total sum of values from a list of JSON objects be calculated in an HTML document?

I am currently designing an HTML form that, upon submission of a user's name, should return an integer representing the sum of all purchased items by the user. The API response is in JSON format and appears as follows: [{"Phone":800}, {"laptop":1500} ...

Issue with uninterrupted playback on html5 audio player when pages are loaded using Infinite Scroll

I'm currently designing a website that features 20 individual song audio players on each page. The code I have implemented is intended to automatically play the next visible song once the current song finishes playing. Everything works perfectly on th ...

What is the best way to display a multi-state component that includes an API fetch?

Currently, my tech stack includes React and Node.js. Within my project, I have a component named ItemList. This particular component fetches data from an API in the componentDidMount() method to facilitate rendering a "loading state." My objective is to ...

Suggestions for resetting the input field IDs in a cloned div after deletion

In the given HTML code snippet, there is a <div> containing two input fields as shown below: <button type = "button" id = "add-botton" >Add Element </button> <div id = "trace-div1" class = "trace"> <h4><span>Trac ...

What are the steps to creating a unique event within an AngularJs service?

In the midst of my AngularJs project, I find myself faced with a dilemma. I have a service designed to manage button events, but I want another service to handle these events indirectly without directly interacting with the buttons themselves. So, my goal ...

"Hiding elements with display: none still occupies space on the

For some reason, my Pagination nav is set to display:none but causing an empty space where it shouldn't be. Even after trying overflow:hidden, visibility:none, height:0, the issue persists. I suspect it might have something to do with relative and ab ...

Simulating dependencies of Angular 2 components during unit testing

Struggling with accessing mocked service methods in Angular 2 during component unit testing. Seeking guidance on a standard approach, despite following Angular docs closely. The challenge lies in reaching the mocked service's methods. My immediate go ...

Incorporate titles for items in the jquery caroufredsel plugin

I am currently using the second example of the caroufredsel plugin, which can be found on this page . I am attempting to add a caption for each picture. To achieve this, I have used `li` and `lis` in my HTML code: <div class="list_carousel"> &l ...

Top method for identifying discrepancies in 2 arrays of objects

I'm currently working with two arrays of objects and trying to find the most efficient way to compare them to identify any differences. https://i.sstatic.net/fIPnA.png I apologize for posting the image, but I felt it was necessary for better clarit ...

The Angular error TS2531 occurs when attempting to call scrollIntoView on an object that may be null

In my current Angular project, I am attempting to implement a scroll view using ViewChild by id. This is the method I have written: ngOnInit() { setTimeout(() => { if (this.router.url.includes('contact')) { ...

Printing a list of values from a C# page to the presentation layer (ASPX)

I am dealing with a list object in my Cs page that has 2 rows. So, how can I access it separately on my Aspx page? For instance, for a single value, the code would look like this: $("#txtBilldate").val(data.d.lphBillDate); But how can I retrieve a list ...

Unable to extract the output from the JSON data; instead, I retrieve an undefined result

I am having trouble accessing SpeechRegions data in Channel from SpeechRegions. When I use the code "console.log(speech.Channels)", it displays the json data shown below. However, when I try "console.log(speech.Channels.SpeechRegions)", it returns undefi ...

Is it possible to make multiple requests in node.js using npm and then wait for all of them to finish

I am currently working on a program that needs to make 3 separate requests to 3 different URLs. The issue I'm facing is that the program takes about 1.5 seconds to run through all 3 requests because it waits for each request to complete before moving ...

Positioning a div on the right side of its parent div

Hi there! I'm currently working on a small navbar that has two sections: the left section with an arrow icon and the right section with two icons - an envelope and an exclamation triangle. I've been trying to position the right section in the top ...

Ways to eliminate type errors when coding in TypeScript and prevent them from occurring in the following code

const obj = { extend: (p: { property: string; methods: { name: string; call: string; params: number }[]; }) => { obj[p.property] = {}; p.methods.forEach((m) => { obj[p.property][m.name] = (params: any[]) => m.call ...

Building a User Info Form in React and Redux: A Step-by-Step Guide

After successfully retrieving user information using an axios request and rendering it on a view with a custom component, I encountered a problem trying to display the same information on another component called ProfileForm. The ProfileForm component is m ...