如何在 div 的顶部和底部获得水平滚动条?
因为我很确定没有原生的 html 或 CSS 方法可以做到这一点,所以我愿意使用 JavaScript 来做到这一点。显然,我可以使用 CSS 中的 overflow: auto
在 div 底部获得一个滚动条。是否有一些 JavaScript 可以从底部“克隆”滚动条并将其放置在 div 的顶部?也许还有另一种方法?
Since I'm pretty sure there is no native html or CSS way of doing this, I'm open to doing this with JavaScript. Obviously, I can get a scrollbar at the bottom of my div using overflow: auto
in CSS. Is there some JavaScript that could "clone" the scrollbar from the bottom and place it at the top of the div? Maybe there's another way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在真实元素之上创建一个新的虚拟元素,具有相同的内容宽度以获得额外的滚动条,然后将滚动条与
onscroll
事件绑定在一起。这是一个可以改进的概念证明,例如。通过轮询或侦听可能更改
element
的scrollWidth
的事件,例如使用%
长度时调整窗口大小、字体大小更改,或由其他脚本驱动的内容更改。 IE 选择在元素内呈现水平滚动条以及 IE7 的页面缩放也存在(像往常一样)问题。但这是一个开始。You could create a new dummy element above the real one, with the same amount of content width to get an extra scrollbar, then tie the scrollbars together with
onscroll
events.This is a proof of concept that could be improved eg. by polling or listening for events that might change the
scrollWidth
ofelement
, for example window resizes when%
lengths are in use, font size changes, or content changes driven by other scripts. There are also (as usual) issues with IE choosing to render horizontal scrollbars inside the element, and IE7's page zooming. But this is a start.您可以使用 jQuery 的 UI 滑块控件。您可以在 NetTuts 上在线阅读实现此效果的教程:http://net.tutsplus.com/tutorials/javascript-ajax/making-a-content-slider-with-jquery-ui/
You could use jQuery's UI Slider control. You can read a tutorial for acheiving this effect online at NetTuts: http://net.tutsplus.com/tutorials/javascript-ajax/making-a-content-slider-with-jquery-ui/