简体   繁体   English

高度100%自定义滚动条

[英]height 100% custom scrollbar

Is there any library / plugin for a custom scrollbar which supports the height 100% property or just percentage at all? 是否有支持自定义滚动条的库/插件,它支持height 100%属性或仅支持百分比? I've tested like dozens of jQuery scrollbar plugins but none of them seem to work properly without fixed height. 我已经测试了数十个jQuery滚动条插件,但是如果没有固定的高度,它们似乎都无法正常工作。

You could use 你可以用

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

and set the pixel height of the plugin you are trying to use to 并设置您要使用的插件的像素高度

(objHeight.toString() + "px")

To get the innerHeight or innerWidth of other DOM elements with jQuery, try jQuery's own innerWidth/innerHeight() method: http://api.jquery.com/innerHeight/ . 要使用jQuery获取其他DOM元素的innerHeight或innerWidth,请尝试使用jQuery自己的innerWidth / innerHeight()方法: http ://api.jquery.com/innerHeight/。

NOTE: If you have a border on the object, use the normal height and width() methods instead of innerHeight() or innerWidth() since the inner methods include element padding but not borders. 注意:如果对象上有边框,请使用常规的height和width()方法而不是innerHeight()或innerWidth(),因为inner方法包括元素填充但不包括边框。

If you need the scrollbar to scale to height or width changes, create a callback on a jQuery resize event: 如果需要滚动条缩放以更改高度或宽度,请在jQuery调整大小事件上创建一个回调:

var resizeFn = function() {
//do resize calcs with getting height and widths and 
// setting plugin updates to new height and width
}
$(window).resize(functionName);

You've tested dozen plugins, but miss some: try to use jQuery Scrollbar , which does not require height to be set. 您已经测试了十二个插件,但是错过了一些:尝试使用jQuery Scrollbar ,它不需要设置高度。 Also, height can be limited with standard css max-height value in px or % of parent container. 此外,可以使用父容器的px%的标准css max-height值来限制max-height

I've developed a custom scrollbar library named SimpleScrollbar . 我已经开发了一个名为SimpleScrollbar自定义滚动条库

It does not depend on any other library/framework, and it's less than 1KB after gzip and minification. 它不依赖于任何其他库/框架,并且在gzip和压缩后小于1KB。

It uses the native scroll, so there are no hacks, and the performance is awesome. 它使用本机滚动,因此没有黑客,而且性能很棒。


You only need to include the library in your page, and use the ss-container attribute in any div that you want to make scrollable. 您只需要在页面中包括库,并在要使其可滚动的任何div中使用ss-container属性即可。 Live example: 现场示例:

 <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> 


It works on all the modern browsers (Firefox, Chrome, Opera, Safari, Edge), and on IE10 and IE11. 它适用于所有现代浏览器(Firefox,Chrome,Opera,Safari,Edge)以及IE10和IE11。 You can also use it in IE9 by including a classList polyfill. 您还可以通过包含classList polyfill在IE9中使用它。

All Android, iOS and Windows Phone browsers are supported either. 所有Android,iOS和Windows Phone浏览器均受支持。


It supports the height: 100% you asked, as soon as the parent container has a height defined, eg: http://jsfiddle.net/z19w2Lfa/ 它支持height: 100%父容器定义好高度后,您要求的height: 100% ,例如: http : //jsfiddle.net/z19w2Lfa/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM