我尝试为固定位置的左侧边栏实现自定义滚动条,但滚动条不起作用。谁可以向我解释为什么不起作用?我试着强迫"强迫"在内部位置,但没有任何表现。
看看jsfiddle:
https://jsfiddle.net/1tpaeb4b/3/
(function($){
$(window).load(function(){
$(".content").mCustomScrollbar(
{
alwaysShowScrollbar: 2,
axis: "y",
scrollbarPosition: "inside"
});
});
})(jQuery);

#sidebar-left-container{
position: fixed;
height: auto;
width: 25%;
min-width:250px;
bottom: 0;
top:0;
left: 0;
background-color: #fff;
color: #808080;
padding: 15px;
}
#sidebar-left-container h2{
margin-top: 0;
font-size: 1.4em;
}
.truncate{
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
body{
background-color: #f1f1f1;
}

<div id="sidebar-left-container">
<h2><strong><span class="fa fa-comments-o"></span> Conversations</strong></h2>
<div class="content">
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
<div class="media messages">
<div class="media-left">
<a href=""><img src="/img/avatar-small.png" alt="avatar" class="img-circle pull-left message-img margin-right-15px" /></a>
</div>
<div class="media-body position-relative">
<a href=""><h4 class="media-heading"><strong>Alessandro Corradini</strong></h4></a>
<p class="message-text truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est elit, vulputate vitae dignissim non, varius vitae purus. Praesent quis augue malesuada, malesuada est eu, cursus metus.</p>
</div>
</div>
</div>
</div>
&#13;
答案 0 :(得分:1)
你的jsFiddle有很多问题。
首先,您通过HTTP加载了jquery库,jsFiddle不允许这样做。
其次,您附加mCustomScrollbar
的方式有点无效。试试这个:
jQuery(function($) {
$(".content").mCustomScrollbar({
alwaysShowScrollbar: 2,
axis: "y",
scrollbarPosition: "inside"
})
});
然后给你的div.content
一些有限的高度,这样你就可以看到滚动条工作了。
查看您的更新小提琴:https://jsfiddle.net/1tpaeb4b/4/