Issue:
I am facing a problem with two containers that have overflowing text content like this: https://i.sstatic.net/wsasV.png
In this setup, the blue <div>
s have overflow:hidden
applied. Now, I am trying to synchronize the scrolling behavior of these divs in a customized manner, regardless of where I scroll within the white container <div>
. My idea is to create a transparent, absolutely positioned <div>
directly inside the white container and allow it to have overflowing children:
https://i.sstatic.net/06k1a.png
The blue container in this setup has a higher z-index compared to the original two text containers:
.container {
width: 100vw;
height: 100vh;
z-index: 10;
position: absolute;
overflow-y: scroll;
}
This leads to a final visual result like this:
https://i.sstatic.net/32jK5.png
My aim is to be able to scroll the overlay container while still capturing other mouse events (like text selection) in the underlying elements.
What I am trying to achieve is similar to Perforce P4Merge's diff tool, where they have a single vertical scrollbar for two code blocks, allowing scrolling based on the content discrepancy between the two blocks.
Concern:
Considering the limitation that we cannot selectively disable pointer events using the CSS property pointer-events
, is there an alternative method to enable only the scroll event of the overlaying element while redirecting other pointer events to the underlying elements?
Insight:
In the original implementation written in React, I noticed that there was no need for margin-left: -18px;
on the scrollable-container
to display the scrollbar, which is intriguing. Additionally, here is a Codepen snippet for reference: codepen snippet