I am trying to capture a scroll event in Backbone.Marionette.CompositeView, but to no avail.
As an exercise, I rewrite http://www.atinux.fr/backbone-books/ with Backbone.Marionette. As you can see, when you scroll down, more books appear and are displayed (i.e., Infinite scrolling). However, I cannot capture the scroll event on my view.
Here is my (simplified) code:
LibraryView = Backbone.Marionette.CompositeView.extend({ // properties, initializer, etc. events: { 'scroll': 'loadMoreBooks', 'click': 'loadMoreBooks' }, // some functions loadMoreBooks: function(){ console.log("loadMoreBooks"); } });
The full source code can be seen here: https://github.com/davidsulc/backbone.marionette-atinux-books/blob/scroll/assets/javascript/app.js#L86-89
I do not understand that the click event fires correctly, but the scroll event does not. What am I doing wrong?
Edit: so the error was pretty simple at the end ... I passed "el: #content" to the view constructor, but the scroll was defined in CSS by ".library". Therefore, as soon as I changed my DOM from
<div id="content"> <div class="library"> </div> </div>
to
<div id="content" class="library"></div>
everything worked correctly ...
source share