0
我找到了一種方法來使滾動條在下面,它的實際工作,但我不知道如何隱藏原來的滾動條,只顯示圖片中的滾動條,我還是那麼新,請幫助我。使滾動條自定義
HTML: -
<div class="parent">
<div class="scrollbar"></div>
<div class="scrollable">
<p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Cras non nunc eget sapien molestie mollis.
Proin vestibulum vehicula varius. Duis a nunc ac risus facilisis consectetur.</p>
</div>
</div>
CSS: -
.parent{
position:relative;
margin:50px;
overflow:hidden;
height:200px;
width:180px;
background:#ddd;
}
.scrollable{
overflow-y:scroll;
position:absolute;
padding:0 17px 0 0;
width: 180px;
height:100%;
}
.scrollbar{
position:absolute;
overflow:auto;
top:0px;
right:0px;
z-index:2;
background:#444;
width:7px;
border-radius:5px;
}
的Javascript: -
var $scrollable = $('.scrollable');
var $scrollbar = $('.scrollbar');
$scrollable.outerHeight(true);
var H = $scrollable.outerHeight(true);
var sH = $scrollable[0].scrollHeight;
var sbH = H*H/sH;
$('.scrollbar').height(sbH);
$scrollable.on("scroll", function(){
$scrollbar.css({top: $scrollable.scrollTop()/H*sbH });
});
是什麼瀏覽器您使用?在Chrome中,原始滾動條隱藏起來! –
我正在使用Chrome – pexichdu
將'width:100%;'添加到'.scrollable' css –