javascriptmcustomscrollbar

Why addClass() is not working? Use mCustomScrollbar


JSFiddle

HTML

<ul class="menu" data-mcs-theme="dark">
  <li><a href="#" id="view-all">View All</a></li> 
  <li><a href="#">Test</a></li> 
  <li><a href="#">Test</a></li> 
  <li><a href="#">Test</a></li> 
  <li><a href="#">Test</a></li> 
  <li><a href="#">Test</a></li> 
  <li><a href="#">Test</a></li> 
  <li><a href="#">Test</a></li>  
</ul>

CSS

.menu {
    height: 100px;
    overflow: hidden;
}
.menu li {
    list-style: none;
}

JS

$('#view-all').click(function(){
   $('.menu').addClass('mCustomScrollbar');
});

When I click on 'View All' the JS add class 'mCustomScrollbar' but custome scroll dosn't work? Тhanks to all in advance!


Solution

  • Initiate the scrollbar, like this:-

    $('#view-all').click(function(){
        $(".menu").mCustomScrollbar();
    }); 
    

    Fiddle