Moving a DIV below a fixed-positioned element

I have a website with a scrollable div. It works well, but I also need an absolutely positioned div on top of it - and it still needs to scroll smoothly without any hindrance.

You can check out a basic JSFiddle demonstration here: http://jsfiddle.net/41rawrks/

When you try to scroll the div using the mouse wheel or trackpad, the scrolling is interrupted when the cursor hovers over the other element. Is there a way to fix this issue?

I suspect that the DOM stops recognizing the cursor as being over the scrollable element once it reaches the draggable one (even though the draggable element is placed absolutely within the scrollable element).

How can I resolve this problem?

I didn't think it was feasible, but I found a site that accomplishes it!

Answer №1

If you adjust the overflow property from #scrollDiv80s to its parent element #wrapper80s, the desired functionality is achieved:

#scrollDiv80s div {
    border: 1px solid black;
}
#wrapper80s, #wrapper90s, #wrapper00s {

    overflow-y: scroll; /* Updated */
    overflow-x: hidden; /* Updated */
    height: 100%;
    padding-left: 0px;
    padding-right: 0px;
    position: relative;
}
.decadeHeader {
    background-color: red;
    position: absolute;
    width: 100%;
    z-index: 99999;
    font-size: 28px;
    text-align: center;
}
.decadeHeader:hover {
    cursor: grab;
    cursor: -webkit-grab;
}
#scrollDiv80s {
    /* Removed overflow property from child element */
    border: none;
    height: 100%;
}

Answer №2

The answer consisted of a combination of previously mentioned strategies.

pointer-events: none resolved the issue of the scroll getting stuck, but it also interfered with the dragging functionality. The solution involved adding pointer-events: none to the draggable element only when the column was not scrolling.

Monitoring the scroll event (without mouseclick) was straightforward, I utilized the jQuery debounce to identify when the scrolling had come to a halt.

scrollers.scroll($.debounce( 250, function(){
    // Re-enable drag event
    $(this).next('.decadeHeader').css('pointer-events', 'auto');
}));

A simple yet effective solution!

Answer №3

The element .decadeHeader remains static and does not scroll, allowing it to transfer the scroll event to the element below. In order for this to function properly, you will need to insert some child elements into .decadeHeader, such as:

Simply include the script "_ezswipe.js" from https://github.com/TNT-RoX/android-swipe-shim within your HTML file.

<script src="_ezswipe.js" type="text/javascript"></script>

Then assign the class "_ezswipe" to

<div class="decadeHeader ui-draggable ui-draggable-handle _ezswipe">

Lastly, implement a bit of code to propagate the event.

function catchEvent(e) {
    document.querySelector('#scrollDiv80s').scrollTop += (e.detail.delta.y*-1);
}
var el = document.querySelector("._ezswipe");
el.addEventListener("swipeMove", catchEvent, true);

View the Fiddle here http://jsfiddle.net/41rawrks/7/

Answer №4

To prevent interaction with the blocking element, one option is to utilize pointer-events: none in CSS (although this may not be supported in IE10 and earlier versions). Another approach could involve including e.preventDefault in a mouseenter or mouseover event for that particular element.

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

Angular JS is failing to update views when passing dynamic IDs

I have implemented a method in my controller where I pass a dynamic id using the ng-init function, fetch a response through ajax calls, and try to print the response. However, I am facing an issue as the response is not getting printed. I am using ng-repea ...

Issue: Attempting to access the `userName` property on an undefined object (`tem`), resulting in a TypeError while using flalist

A concern has arisen with the React Native Flatlist as it fails to render properly. What steps should be taken in this scenario? Below is the code snippet for reference: Image description available here import React, {useState, useEffect} from 'react ...

Can the data retrieved from a jsonp call that may be considered "bad" be utilized effectively?

When making a JSONP call to another domain, I am receiving data that is in JSON format but not wrapped in a function. This causes a parse error to occur. However, the data is still retrievable and visible. Despite the error, is it possible to utilize the ...

How to retrieve URL parameters from within the when() function in AngularJS

Consider the code snippet below: $routeProvider.when('/movies/:type', { title: 'Movies', templateUrl: 'pages/movies/movies.html', controller: 'MoviesCtrl' }); Is there a way to retriev ...

The process of running npx create-react-app with a specific name suddenly halts at a particular stage

Throughout my experience, I have never encountered this particular issue with the reliable old create-react-app However, on this occasion, I decided to use npx create-react-app to initiate a new react app. Below is a screenshot depicting the progress o ...

What distinguishes running rm -rf node_modules + npm i from using npm ci?

When using a Unix system and needing to clean out the node modules folder, is there any benefit or distinction between executing rm -rf node_modules followed by npm i as opposed to npm ci My understanding is that both yield the same outcome, but is th ...

npm installs a multitude of dependencies

Recently, I purchased an HTML template that includes various plugins stored in a directory named bower_components, along with a package.js file. While trying to add a new package that caught my interest, I opted to utilize npm for the task. Upon entering ...

Issue with running `npm start` in React after installing React script version 3.4.0

I'm new to React.js and I've been having trouble getting it to work after using npm start. No matter what I try, I can't seem to get it running. Any help would be appreciated. Error [email protected] start C:\xampp\htdocs& ...

Encountering a tucked-away issue with the Safari scroll bar?

Encountered an interesting bug where users are unable to scroll down a text nested inside a div. This issue seems to be isolated to Safari, as it doesn't occur in other browsers. I have prepared a sample file to demonstrate the bug and would apprecia ...

What is the process for accessing jQuery methods in Node.js?

When working on the client side, using Object.keys($.fn) (or Object.keys(jQuery.fn)) is a simple way to retrieve jQuery functions as an array. But how can I achieve the same result of getting this array with the jquery package from npm? I attempted: re ...

Struggling to close (or conceal) a modal following an ajax request

I have a JavaScript function that sends data to a PHP script. The goal is to hide a div with the class "reveal-modal-refer" and then load a short script from '../message_alerts/refer_message_box.php' into another div with the class 'reveal-m ...

Suggestions for this screenplay

I am completely new to the world of coding and computer languages, and I could use some guidance on how to utilize this script for a flash sale. setInterval(function() { var m = Math.floor((new Date).getTime()/1000); if(m == '1476693000000& ...

Downloading EJS File instead of Displaying on Express.js Router

As I embark on the journey of developing a live video sharing/watching feature using Pure Node.js and without relying on any frameworks, an unexpected issue arose in the middle of the process. The problem occurred when Express started downloading an EJS fi ...

retrieve information in json format from a specified web address

I need to figure out why the data from a specific URL is not being displayed properly on my node application. It seems like there might be an error in my code. const extractRefDefaultSchema = async (data) => { const url = "https://mos.esante.gouv.f ...

Guide on implementing a live media stream using JavaScript

I am looking to set up a live audio stream from one device to a node server, which can then distribute that live feed to multiple front ends. After thorough research, I have hit a roadblock and hope someone out there can provide guidance. I have successf ...

What is the reason for a jQuery load to fail when www is included in the URL?

Can anyone explain why adding www to an ajax request causes it to fail? For example, this code works fine: $('#mydiv').load(''); But this one doesn't work (returns empty): $('#mydiv').load(''); It's wo ...

Sending data to API using AngularJS Http Post

Upon clicking "Add new User", a modal pop-up will appear with a form containing a text field and a checkbox. However, upon clicking the create button, the data is not being posted to the API and the modal pop-up remains open without closing. I would like ...

What is the best way to eliminate a specific character from the key of an array of objects using JavaScript?

My JavaScript object looks like this: result = [ {"Account_ID__r.Name":"Yahoo Inc Taiwan","Contact_ID__r.Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="42283427302c2d2e2602362a27313 ...

Preventing default form submission in jQuery: How to cancel it when a certain condition is met

I have a contact form where I validate the input values upon clicking on the submit button. If there is at least one empty input, I trigger an alert and prevent the form submission by using preventDefault. However, if all inputs are filled and submitted, t ...

Bootstrap button groups do not support the checking functionality of radio buttons

My bootstrap modal contains a form with two radio style buttons created using the example for normal button styled radio options found here: <form id="changePlanForm" action="/change_plan_submit.php" method="post"> & ...