13

I got a div, and to make it fancier I use the SlimScroll jQuery plugin on that div

$('#scrollable').slimscroll({
   color: '#900',
   size: '8px',
   width: '300px',
   height: '500px'
});

now there's a moment when I want this div not to have this property anymore (but to have the browser default scrollbar). How can I remove the slimscroll?

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
Andrea Silvestri
  • 1,082
  • 4
  • 14
  • 41

7 Answers7

18
$("#scrollable").slimScroll({destroy: true});
ink
  • 649
  • 1
  • 9
  • 22
6

I made this function which works great in my case

function destroySlimscroll(objectId) { 
   $("#"+objectId).parent().replaceWith($("#"+objectId)); 
}
Andrea Silvestri
  • 1,082
  • 4
  • 14
  • 41
6

I did this and it works better than any other solution I saw..

$(".slimScrollBar,.slimScrollRail").remove();
$(".slimScrollDiv").contents().unwrap();
Qirel
  • 25,449
  • 7
  • 45
  • 62
Daniel Maiochi
  • 607
  • 6
  • 16
2

Try calling destroy method on it, hopefully it supports.

$('#scrollable').slimscroll("destroy");

You can also remove all inline styles applied by the plugin

$('#scrollable').attr('style', '');
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
1

I was having trouble doing this in a large SPA app. scroll's just kept piling up on top of each other, even with calling the destroy method of slimScroll.

So here's my solution.

$('.slimScrollBar,.slimScrollRail').remove();
$('.slimScrollDiv').each(function(){
    $(this).replaceWith($(this).children());
})

This code runs and destroys all scrolls, then the controllers are free to bind scrolls as needed.

r3wt
  • 4,642
  • 2
  • 33
  • 55
0

None of the answers worked for me so I thought I would share my solution.

I load a function called handleScroller() on document.ready(). When I perform an update on the ul li I call the handleScroller() function again in order for the slimScrollDiv to become destroyed and rebuilt again. I set the height of the ul container also. It seems to be working quite well. Here is a sample of my code:

CSS in style.css .scroller{height: 182px;}

HTML/Bootsrap menu

<ul class="nav navbar-nav pull-right">
   <!-- slimScroll notifications -->
   <li id="header_notification_bar"  class="hidden dropdown">
   <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
    <i class="fa fa-bell"></i>
        <span class="badge">
            6
        </span>
   </a>
   <ul id="notifications" class="dropdown-menu extended"></ul>
   </li>
<!--other menu items ... //-->
</ul>

JS/jQuery

$(document).ready(function(){
   handleScroller();
   VisitedHandler(); 
});

function VisitedHandler(){
   $("#notifs li").on("click",function(){

      $("#notifications").html('');     
      $('ul#notifs').html('');
      $("#notifications").append('<li><ul id="notifs" class="dropdown-menu-list scroller"></li>');
       var ul = $('#notifs');
           ul.append('<li id="general">New Announcement</li>')   
           ul.append('<li id="enhancements">New Page Enhancements</li>'); 

    handleScroller();

});
}

function handleScroller(){
  $("#notifs").slimscroll({destroy:true});
     var notes = $("#notifs");
     var height = notes.css("height");
     if($('#notifs .nws').size() < 5 && $('#notifs .nws').size() != 0)
        height = $('#notifs .nws').size() * 40 + 22;
     else      
        height = 182;
     //no Notifications
     if($('#notifs .nws').size() == 0)
        height = 0;
   $("#notifs").slimScroll({
    size: '10px',
    color: '#a1b2bd',
    railColor:'#272727',
    position: 'right',
    height: height,
    alwaysVisible: true,
    railVisible: true,
    disableFadeOut: true
   });
}

NOTE: There is a solution here that wraps the handleScroller() logic around a setInterval(). I suggest staying away setInterval() if possible.

yardpenalty.com
  • 1,244
  • 2
  • 17
  • 32
0

To enable slimscroll and disable slimscroll $('#scrollable').slimscroll("destroy");