Removing slimscroll from div
Asked Answered
T

7

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?

Tiaratibbetts answered 5/2, 2012 at 19:22 Comment(0)
T
6

I made this function which works great in my case

function destroySlimscroll(objectId) { 
   $("#"+objectId).parent().replaceWith($("#"+objectId)); 
}
Tiaratibbetts answered 9/8, 2013 at 8:52 Comment(3)
could you do this in Fidle ??Pleinair
Ok, give me some time!Tiaratibbetts
This will leak memory, because the event subscriptions aren't disposedGentlemanfarmer
K
18
$("#scrollable").slimScroll({destroy: true});
Katlaps answered 12/3, 2014 at 7:43 Comment(6)
Was it always there or they added this function in a recent update?Tiaratibbetts
Can't be sure, but I think it was added after your question. It works for version 2 and newer.Katlaps
version 2 of jquery or the plugin?Tiaratibbetts
The SlimScroll plugin's version.Katlaps
This will leak memory, because the event subscriptions aren't disposedGentlemanfarmer
@Katlaps The plugin's version is still only 1.3.8 five years later, I'm not sure how you have version 2?Encyclopedia
T
6

I made this function which works great in my case

function destroySlimscroll(objectId) { 
   $("#"+objectId).parent().replaceWith($("#"+objectId)); 
}
Tiaratibbetts answered 9/8, 2013 at 8:52 Comment(3)
could you do this in Fidle ??Pleinair
Ok, give me some time!Tiaratibbetts
This will leak memory, because the event subscriptions aren't disposedGentlemanfarmer
D
6

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

$(".slimScrollBar,.slimScrollRail").remove();
$(".slimScrollDiv").contents().unwrap();
Demetria answered 25/2, 2016 at 14:54 Comment(0)
G
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', '');
Gratia answered 5/2, 2012 at 19:28 Comment(4)
unfortunately the only thing it does is destroying my settings and set the default ones...Tiaratibbetts
ok I'm noticing that the plugin creates a wraps $('#scrollable') with a div and it styles it. So I have to remove that wrapper (which it just has a class) but keep my $('#scrollable') which is in it...Tiaratibbetts
I made this function which works great in my case function destroySlimscroll(objectId) { $("#"+objectId).parent().replaceWith($("#"+objectId)); }Tiaratibbetts
Thank you... I forgot to answer myself. Vote up when I do, please =DTiaratibbetts
P
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.

Precessional answered 24/1, 2016 at 7:4 Comment(0)
A
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.

Asphyxiate answered 10/9, 2016 at 23:6 Comment(0)
A
0

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

Autum answered 19/4, 2017 at 7:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.