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.