我有一个带圆角的<div>
。我实际上将它用作下拉菜单的下拉列表部分。不可避免地,每隔一段时间它就会包含大量信息,所以它只需要一个滚动条。但是,当显示滚动条时,它会移除该侧的圆角,这是非常不希望的。这是jsFiddle。
#test {
background: red;
max-width: 200px;
max-height: 200px;
border-radius: 10px;
overflow-y: scroll;
}
<div id="test">
Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br /> Text
<br />
</div>
我尝试使用自定义解决方案,比如jQuery的mCustomScrollBar,我喜欢它,但它与圆角完全相同。有关如何解决此问题的任何变通方法或提示?
答案 0 :(得分:1)
您可以使用jQuery插件jScrollPane,并根据需要自定义颜色,宽度等。
请参阅以下OS X样式滚动条示例。有关动态宽度,请参阅here。
<强> jsFiddle 强>
$(function() {
$('.scroll-pretty').jScrollPane({
verticalGutter: 2
});
});
.scroll-pretty {
background: grey;
border-radius: 5px;
width: 300px;
height: 150px;
overflow: auto;
outline: 0;
}
.scroll-pretty .jspVerticalBar {
background: transparent;
width: 10px;
}
.scroll-pretty .jspTrack {
background: transparent;
width: 8px;
}
.scroll-pretty .jspCap {
background: transparent;
display: block;
height: 2px; /*same as verticalGutter value*/
}
.scroll-pretty .jspDrag {
background: silver;
border-radius: 10px;
}
.scroll-pretty p {
margin: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jScrollPane/2.0.23/script/jquery.jscrollpane.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jScrollPane/2.0.23/style/jquery.jscrollpane.min.css">
<div class="scroll-pretty">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in ligula id sem tristique ultrices eget id neque. Duis enim turpis, tempus at accumsan vitae, lobortis id sapien. Pellentesque nec orci mi, in pharetra ligula. Nulla facilisi. Nulla facilisi.
Mauris convallis venenatis massa, quis consectetur felis ornare quis. Sed aliquet nunc ac ante molestie ultricies. Nam pulvinar ultricies bibendum. Vivamus diam leo, faucibus et vehicula eu, molestie sit amet dui. Proin nec orci et elit semper ultrices.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed quis urna mi, ac dignissim mauris. Quisque mollis ornare mauris, sed laoreet diam malesuada quis. Proin vel elementum ante. Donec hendrerit arcu ac odio tincidunt
posuere. Vestibulum nec risus eu lacus semper viverra.
</p>
</div>