Malihu Custom Scrollbar with Backbone

83 views
Skip to first unread message

Patrick Caillouet

unread,
Jan 23, 2017, 5:19:34 PM1/23/17
to backbonejs
Hi everyone. I'm new to backbone but not HTML/JS/CSS.

I'm trying to get a custom scrollbar to work inside one of my views.

I found this popular library: https://github.com/malihu/malihu-custom-scrollbar-plugin

But I'm having a hard time using it with backbone.

The library supports 2 ways of using the scrollbar... with custom html attribute... or with javascript.

If I try to setup the scrollbar with javascript like this:

$("selector").mCustomScrollbar();

it doesn't work.. I can see it did try to do something (as I see classes added etc), but doesn't work.

But if I use the html attributes like this:

<div class="mCustomScrollbar" data-mcs-theme="dark">
  <!-- your content -->
</div>

It does work.

If I try doing this without backbone, and jquery alone, everything works fine.

here is the code for my view:

var TestView = Backbone.View.extend({
    tagName
:"div",
    initialize
:function(){
       
this.$el.html("<div id='scrollbar'></div>");

       
this.thescrollbar = this.$el.find("#scrollbar");
       
this.thescrollbar.mCustomScrollbar();

   
}
});

Is there something else I need to do to use 3rd party libraries like this with backbone?


Reply all
Reply to author
Forward
0 new messages