2

是否有任何支持高度 100% 属性或仅支持百分比的自定义滚动条的库/插件?我已经测试了几十个 jQuery 滚动条插件,但如果没有固定高度,它们似乎都不能正常工作。

4

3 回答 3

0

你可以使用

var objHeight = window.innerHeight;// to get the pixel height

并设置您尝试使用的插件的像素高度

(objHeight.toString() + "px")

要使用 jQuery 获取其他 DOM 元素的 innerHeight 或 innerWidth,请尝试使用 jQuery 自己的 innerWidth/innerHeight() 方法:http ://api.jquery.com/innerHeight/ 。

注意:如果对象上有边框,请使用正常的 height 和 width() 方法而不是 innerHeight() 或 innerWidth(),因为内部方法包括元素填充但不包括边框。

如果您需要滚动条缩放到高度或宽度更改,请在 jQuery 调整大小事件上创建回调:

var resizeFn = function() {
//do resize calcs with getting height and widths and 
// setting plugin updates to new height and width
}
$(window).resize(functionName);
于 2013-10-11T13:31:31.187 回答
0

您已经测试了十几个插件,但错过了一些:尝试使用jQuery Scrollbar,它不需要设置高度。此外,可以使用父容器中的标准cssmax-height值限制高度。px%

于 2014-03-19T11:04:33.957 回答
0

我开发了一个名为 SimpleScrollbar 的自定义滚动条库

它不依赖于任何其他库/框架,gzip 和缩小后小于 1KB。

它使用本机滚动,因此没有 hack,性能也很棒。


您只需要在您的页面中包含该库,并ss-container在您想要使其可滚动的任何 div 中使用该属性。现场示例:

<link href="http://buzinas.github.io/simple-scrollbar/simple-scrollbar.css" rel="stylesheet"/>
<div style="height: 180px; width: 200px; display: inline-block;" ss-container>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<section style="height: 180px; width: 300px; display: inline-block;" ss-container>
  <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
      <p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</p>
</section>
<!--[if IE 9]><script src="https://cdn.jsdelivr.net/classlist/2014.01.31/classList.min.js"></script><![endif]-->
<script src="http://buzinas.github.io/simple-scrollbar/simple-scrollbar.min.js"></script>


它适用于所有现代浏览器(Firefox、Chrome、Opera、Safari、Edge)以及 IE10 和 IE11。您还可以通过包含一个 classList polyfill 在 IE9 中使用它。

也支持所有 Android、iOS 和 Windows Phone 浏览器。


它支持height: 100%你问的,只要父容器定义了高度,例如:http: //jsfiddle.net/z19w2Lfa/

于 2015-09-06T14:42:10.407 回答