javascript - 高度 100% 自定义滚动条

标签 javascript css scrollbar

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

最佳答案

你可以使用

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

关于javascript - 高度 100% 自定义滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19317904/

相关文章:

php - 无法弄清楚如何定义输入框的宽度

html - Angular 模态内的 ng-scrollbar

html - Webkit 中的裁剪滚动条和边框

javascript - 如何在回调中访问正确的“this”?

javascript - 如何在 ng-click 到父元素后添加类 CSS?

javascript - 将 CSS "stripe"效果应用于 JavaScript 中动态插入的表格行

jquery - 自定义我网站上的滚动条

javascript - 使用 Mongoose 在 JSLint 中抑制 `Expected an identifier and instead saw ' default'(保留字)

javascript - Chrome 扩展连接脚本 - 引用资源

javascript - ajax 不工作,不显示 php 数据