如何禁用 jScrollPane (JQuery) 中的水平滚动条?
你们能让我知道禁用水平滚动条的最佳方法是什么吗?
我有 width: 100%
和 height:280px
的 div。当我们有很长的连续文本(没有任何空格)时,我们会显示一个水平滚动条。
顺便说一句,我正在使用 jscrollPane。
任何建议将不胜感激。
Can you guys please let me know what is the best way to disable the horiontal scroll bar?
I have div with width: 100%
and height :280px
. When we have long continuous text (without any spaces), we are getting a horizontal scrollbar displayed.
Btw I am using jscrollPane.
Any suggestions would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我在jScrollPane - 设置对象文档中发现了什么:
因此,要摆脱水平条,只需将内容宽度设置为低于容器宽度即可。
例子:
What I have found in jScrollPane - settings object documentation:
So to get rid of horizontal bars, just set content width lower than the container width.
Example:
Sławek Wala (
contentWidth: '0px'
) 的答案确实是一根魔杖:)在 IE8 中,不必要的水平滚动条经常出现在弹性容器上。但这只是问题的一部分:当水平滚动条出现时内容会通过垂直装订线和滚动条溢出。
因此,如果禁用水平滚动条只是使其不可见(正如其他答案所建议的那样),那么问题的第二部分仍然存在。
contentWidth: '0px'
修复了这两个症状。然而,knowncitizen 是对的,“0px”对 jScrollPane 做了一些奇怪的事情,因为 contentWidth 是一个整数属性(顺便说一句
contentWidth: 'foo'
给出我们得到了同样漂亮的结果)。为了避免不可预测的影响,可以使用任何正数但足够小的数字,如下所示:
contentWidth: 1
The answer from Sławek Wala (
contentWidth: '0px'
) is a really magic wand :)In IE8 unnecessary horisontal scrollbar appears often upon elastic containers. But that's only part of the trouble: when horisontal scrollbar appears the content overflows through both vertical gutter and scrollbar.
So, if one disables horisontal scrollbar just making it invisible (as the other answers suggest) then the second part of the trouble remains.
contentWidth: '0px'
fixes the both symptoms.However, knowncitizen was right, '0px' does something weird with the jScrollPane because contentWidth is an integer property (btw
contentWidth: 'foo'
gives us the same pretty result ).To avoid unpredictable effects one can use any positive but small enough number like this:
contentWidth: 1
这是一个相当过时的问题。但如果有人遇到与你和我相同的问题:
由于我没有找到任何属性或 API 调用来实现此目的,我使用了简单的解决方案 - 通过 CSS 禁用:
.jspHorizontalBar { display: none !important; 不是很优雅的
方式,但节省了调查或“破解”jScrollPane 代码的时间。
This is quite outdated question. But in case someone has same issue as you and I:
as I haven't found any property or API call to achieve this, I used simple solution - disabled via CSS:
.jspHorizontalBar { display: none !important; }
Not very elegant way, but saved time of investigating or 'hacking' jScrollPane code.
将
horizontalDragMaxWidth: 0
传递给选项。Pass
horizontalDragMaxWidth: 0
to the options.这里没有一个解决方案对我有用,所以这是我使用嵌套 div 所做的:
JS
HTML
None of the solutions worked for me here so here's what I did using nested divs:
JS
HTML
我能够使用 CSS 来完成此任务。
由于父级应该具有类
horizontal-only
,当我们只想要一个水平条时,我添加了类jspVerticalBar
作为子级,这样当它仅出现在 < code>horizontal-only 类,它不会显示它。如果您在同一页面上设置了垂直和水平,它仍然有效。
I was able to accomplish this using CSS.
Since the parent should have the class
horizontal-only
, when we only want a horizontal bar, I added the classjspVerticalBar
as a child so that when it appears ONLY under thehorizontal-only
class, it will not display it.It will still work if you have set the vertical and horizontal on the same page.
在尝试其他答案但失败后,我们不得不破解 jScrollPane 才能完成这项工作。在 jquery.jscrollpane.js 中,第 171 行:
不确定它有多安全,但这对我们有用。
After trying and failing with the other answers, we had to hack jScrollPane to make this work. In jquery.jscrollpane.js, line 171:
Not sure how safe it is but that works for us.
对我来说,最好的解决方案是在 CSS 中为
.customSelect
和.jspPane
类添加left: 0 !important;
:For me, the best solution was in to add
left: 0 !important;
for classes.customSelect
and.jspPane
in the CSS: