gpt4 book ai didi

javascript - 在父 div 上滚动的同时滚动子 div

转载 作者:行者123 更新时间:2023-11-28 04:36:48 25 4
gpt4 key购买 nike

当用户在父级 div 上滚动时,子级应滚动到最后,然后页面滚动应继续。

我尝试了这种反向逻辑 Scrolling in child div ( fixed ) should scroll parent div

但是不起作用。请建议如何使其正常工作。

.scrolling-child{ height: 50px; width:400px; border:1px solid green; overflow:scroll; }
.parent { height: 5000px; width:100%; padding: 20px 0; border:1px solid red; overflow:scroll;}
<div class="parent">
<div class="scrolling-child">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>

最佳答案

如果我理解正确,只需添加position:fixed;到滚动子 div。见下文。

.scrolling-child{height: 50px; width:400px; border:1px solid green; overflow:scroll; position:fixed;}

.parent {height: 5000px; width:100%; padding: 20px 0; border:1px solid red; }
<div class="parent">
<div class="scrolling-child">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>

关于javascript - 在父 div 上滚动的同时滚动子 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com