gpt4 book ai didi

javascript - Jquery 自定义滚动条(Malihu - mCustomScrollBar)不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 10:44:02 25 4
gpt4 key购买 nike

我尝试为具有固定位置的左侧边栏实现自定义滚动条,但滚动条不起作用。谁能给我解释一下为什么不起作用?我试图“强制”进入内部位置,但没有出现。

看看 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>

最佳答案

你的 jsFiddle 有很多问题。

首先,您通过 HTTP 加载了 jquery 库,而 jsFiddle 不允许这样做。

其次,您附加 mCustomScrollbar 的方式有些无效。试试这个:

jQuery(function($) {
$(".content").mCustomScrollbar({
alwaysShowScrollbar: 2,
axis: "y",
scrollbarPosition: "inside"
})
});

然后给你的 div.content 一些有限的高度,这样你就可以看到滚动条工作了。

查看更新后的 fiddle :https://jsfiddle.net/1tpaeb4b/4/

关于javascript - Jquery 自定义滚动条(Malihu - mCustomScrollBar)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35583762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com