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

标签 javascript jquery html css scroll

当用户在父级 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/

相关文章:

javascript - 为什么我的 jquery .each() 函数不能正常工作?

html - 跨度之间的CSS过渡问题

javascript - 带有 typescript 的 Angular-js - 数据应该存储在 Controller 还是服务中?

javascript - 尝试将路由器注入(inject) app.component.ts 时出错

javascript - 我需要使用 "document.getElementById"

jquery - 如何配置 Tomcat7 以使用 Jquery?

javascript - 如何像StackOverflow确认框一样显示确认框?

jquery - Blueimp文件上传: my DELETE link doesn't work

javascript - 使用canvas根据相机绘制网格

html - Flexbox:如何对齐推向相反方向的 Logo 和内联导航栏