I’m trying to achieve a similar I saw here
but the content of each section should also be scroll-able i.e. they should only stick when the bottom of the section has been reached.
for example when the content is 200vh
like this:
section {
position: sticky;
top: 0;
height: 200vh;
}
section img{
width:100%;
height:100%
}
section:nth-of-type(1) {
background: rgb(225, 204, 200);
}
section:nth-of-type(2) {
background: rgb(240, 216, 163);
}
section:nth-of-type(3) {
background: rgb(192, 211, 217);
}
<section>
<img src="https://picsum.photos/id/128/800/300" alt="">
</section>
<section>
<img src="https://picsum.photos/id/48/800/300"alt="">
</section>
<section>
<img src="https://picsum.photos/id/42/800/300" alt="">
</section>
as you can see 1 & 2 sections stick to the top & we can’t scroll through it’s photo
but the last section works perfectly.
so how do I achieve this effect? Ideally with pure css but I’m open to a javascript solution
2
Answers
I found a solution! Using a one liner in javascript to set the
top
Though I'm not sure if this will work if the window is resized
but you can always use
onresize
to cover that caseI'm still open to a pure css solution if there is one?
I has able to solve this by wrapping the sections into a main div section and few extra lines of css however to achieve the exact same style as the example you gave the sections have to be 100vh. With 200vh this solution still works but you’ll have to do some extra scrolling to reach the next slide. I have prepared a codejs fiddle here with the working code, simply change 100vh to 200vh to see if it works for you.