1

How to make two div's scroll at the same time? I have two div's with text, but one div is bigger and I want to scroll both of them at the same time.

Any ideas?

.content {
  width: 100%;
}

.left {
  background-color: yellow;
  width: 50%;
  float: left;
  max-height: 200px;
}

.right {
  background-color: green;
  width: 50%;
  float: left;
  max-height: 200px;
  overflow: hidden;
  overflow-y: scroll;
}

jsfiddle here

Adil
  • 240
  • 1
  • 6
  • 19
dar3l
  • 55
  • 1
  • 8
  • 2
    Link to existing post on same question: https://stackoverflow.com/questions/9236314/how-do-i-synchronize-the-scroll-position-of-two-divs – ArcherBoy27 Apr 16 '18 at 12:46
  • Possible duplicate of [How do I synchronize the scroll position of two divs?](https://stackoverflow.com/questions/9236314/how-do-i-synchronize-the-scroll-position-of-two-divs) – Josh Mein Apr 16 '18 at 12:52

3 Answers3

6

So u want to scroll both div's at the same time?

Change your CSS to this:

.content {
  width: 100%;
  max-height: 200px;
  overflow-y: scroll;
}
.left{
  background-color: yellow;
  width: 50%;
  float: left;
}
.right{
  background-color: green;
  width: 50%;
  float: left;
}

Check out this fiddle: https://jsfiddle.net/fhq2kmvb/12/

Jari Rengeling
  • 326
  • 1
  • 15
  • The thing is, I want to scroll green box while I am on yellow box. Note that yellow box doesn't have enough content to be scrollable. I hope it makes sense? – dar3l Apr 16 '18 at 13:10
4

Wasted 5 hours on this.

I had a similar question.
I wanted to overlap & also scroll.

.content {
  position: "relative";
  overflow: "auto";
}
.below{
  font-family: "Courier New", Courier, monospace;
  background-color: yellow;
  position: absolute;
  top: 0px;
  z-index: -1;
  /* width: 100%; */  
}
.above{
  font-family: "Courier New", Courier, monospace;
  position: absolute;
  background-color: transparent;
  top: 0px;
  z-index: 1;
  /* width: 120%; */
}

https://codepen.io/manoharreddyporeddy/pen/XWmpYQL

Hope that helps.

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
0

Maybe something like that could get you started

script

$('.left').scroll(function () {
    $('.right').scrollTop($(this).scrollTop());
});

css

.content {
  width: 100%;
}
.left{
  background-color: yellow;
  width: 50%;
  max-height: 200px;
  float: left;
  overflow: hidden;
  overflow-y: scroll;

}
.right{
  background-color: green;
  width: 50%;
  max-height: 200px;
  float: left;
  overflow: hidden;
  overflow-y: scroll;
}
Anastasios Selmani
  • 3,579
  • 3
  • 32
  • 48