0

Say I have a div #scroll and it's not big enough so the user needs to scroll to see its content.

And I have created an example for this. The div is in red, and it has some content inside. There is also some content outside.

I am looking for a very special experience: if you scroll inside the red div, it can go down to the last li node. But when you keep scrolling, the whole page won't move - unless you scroll outside the red div.

And I hope to make it available for both desktop and mobile.

Is it even possible?

#scroll {
  background:red;
  height:200px;
  overflow-y:scroll
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="scroll">
  <ol>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
    <li>random</li>
  </ol>
</div>

<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>some other content</p>
<p>I don't want to be found if you scroll in the div#scroll</p>
TylerH
  • 20,799
  • 66
  • 75
  • 101
AGamePlayer
  • 7,404
  • 19
  • 62
  • 119
  • I think that the only way to achieve that is to use some JavaScript code. –  Jul 03 '18 at 14:35
  • @Blincer is right, you have to use JS. What you need to do is put an event on div scroll and check for the scroll distance. If the distance is equal to the div height then you return false and no more scrolling. That's it in theory, see what you can find and let me know if I can help you more – yomisimie Jul 03 '18 at 14:39
  • 1
    How would you imagine this working with touch input? – Martin Jul 03 '18 at 15:04

0 Answers0