I know the question sounds confusing, but here's what I'm trying to do - in the snippet below, if the user scrolls through the green div, I want the yellow div to be scrolled accordingly, as if the yellow div had been scrolled.
Note that the yellow div has overflow: auto;, but the green does not.
document.getElementById('green').addEventListener('wheel', function(e){
console.log('scrolled!');
console.log(e.deltaX);
});
#yellow{
background-color: yellow;
display: inline-block;
width: 200px;
height: 200px;
overflow: auto;
vertical-align: top;
padding 20px;
}
#green{
background-color: green;
display: inline-block;
width: 100px;
height: 200px;
vertical-align: top;
}
<div id='yellow'>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
<p>10</p>
</div>
<div id='green'></div>
Run codeHide resultHow do I achieve this?
source
share