【发布时间】:2018-03-27 18:42:48
【问题描述】:
我想为列表添加背景颜色以使滚动看起来更好,但我只想在列表可滚动的情况下使用它。我该如何配置?
【问题讨论】:
我想为列表添加背景颜色以使滚动看起来更好,但我只想在列表可滚动的情况下使用它。我该如何配置?
【问题讨论】:
您可以使用这个简单的检查和修改来满足您的需求:
const dimensions = document.querySelector('selector').getBoundingClientRect();
if(dimensions.height > window.innerHeight) {
// Element's height is bigger than window height, so it should be scrollable
document.querySelector('selector').style('background', '#222');
}
您可以测试元素的高度是否大于其容器的高度。
【讨论】: