12

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
  • 11,376
  • 8
  • 74
  • 105
Andrea Silvestri
  • 992
  • 4
  • 13
  • 38

7 Answers7

16
$("#scrollable").slimScroll({destroy: true});
ink
  • 619
  • 1
  • 7
  • 22
6

I made this function which works great in my case

function destroySlimscroll(objectId) { 
   $("#"+objectId).parent().replaceWith($("#"+objectId)); 
}
Andrea Silvestri
  • 992
  • 4
  • 13
  • 38
6

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

$(".slimScrollBar,.slimScrollRail").remove();
$(".slimScrollDiv").contents().unwrap();
Qirel
  • 21,424
  • 7
  • 36
  • 54
Daniel Maiochi
  • 337
  • 3
  • 13
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
  • 67,648
  • 11
  • 84
  • 121
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,262
  • 2
  • 28
  • 52
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,138
  • 2
  • 15
  • 28
0

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