I'm struggling to come up with the right keywords to search for my issue. I've tried using Google, but it seems my search terms are not effective.
The problem I'm facing involves two relative div
elements with dynamic content. This means that the height of these elements is variable and they can be scrolled through. Let's say the first div
has a class name
of l-content
, representing Left Content, and the second div
has a class name
of r-content
, standing for Right Content.
The l-content
will have more content than the r-content
, but both will be scrollable when the screen size is not large enough to display all the content.
What I want to achieve is for the scrolling in the r-content
to stop once it reaches the end of its content, allowing only the l-content
to continue scrolling.
An example of this behavior can be seen on Facebook where elements like ads and recommendations appear on the right side. When the last element is reached, it appears to fix its position. I am unsure if this is achieved through fixing or another method, but I would like my r-content
to exhibit similar behavior without knowing how to implement it.
Currently, this is what I have coded. Please note that Bootstrap is being used:
CSS
h1 {
font-family: sans-serif;
color: #FFF;
letter-spacing: 2px;
font-weight: 300;
}
.l-content, .r-content {
display: table;
float: left;
margin-bottom: 8px;
text-align: center;
padding: 20px;
}
.l-content {
width: 800px;
height: 2000px;
background: #E04C4E;
margin-right: 8px;
}
.r-content {
width: 430px;
height: 1000px;
background: #5996BC;
}
HTML
<!--LEFT CONTENT-->
<div class="col-lg-8 l-content">
<h1>Left Content with Continue Scrolling.</h1>
</div>
<!--RIGHT CONTENT-->
<div class="col-lg-4 r-content">
<h1>Right Content with Continue Scrolling but scrolling will stop when last content is reached.</h1>
</div>
I am unsure if JavaScript is needed to achieve this effect.
Thank you in advance for any assistance provided.