捕获的div滚动事件 [英] Capture scroll event on div

查看:180
本文介绍了捕获的div滚动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图捕捉Backbone.Marionette.CompositeView内的滚动事件,但没有成功。

I'm trying to capture the scroll event within a Backbone.Marionette.CompositeView, but without success.

作为练习,我重写 http://www.atinux.fr/backbone-books / 使用Backbone.Marionette。正如你所看到的,当你向下滚动,多读书是获取和显示(即无限滚动)。然而,我无法捕捉我的看法的滚动事件。

As an exercise, I'm rewriting http://www.atinux.fr/backbone-books/ using Backbone.Marionette. As you can see, when you scroll down, more books are fetched and displayed (i.e. infinite scroll). However, I'm unable to capture the scroll event on my view.

下面是我(简化)code:

Here's my (simplified) code:

  LibraryView = Backbone.Marionette.CompositeView.extend({
    // properties, initializer, etc.

    events: {
      'scroll': 'loadMoreBooks',
      'click': 'loadMoreBooks'
    },

    // some functions

    loadMoreBooks: function(){
      console.log("loadMoreBooks");
    }
  });

完整的源$ C ​​$ C可以在这里看到:<一href=\"https://github.com/davidsulc/backbone.marionette-atinux-books/blob/scroll/assets/javascript/app.js#L86-89\" rel=\"nofollow\">https://github.com/davidsulc/backbone.marionette-atinux-books/blob/scroll/assets/javascript/app.js#L86-89

我不明白的是,点击事件被触发正确的,但滚动事件不是。我在做什么错了?

What I don't understand is that the "click" event is being triggered properly, but the "scroll" event isn't. What am I doing wrong?

编辑:这样的错误是pretty到底简单......我是路过厄尔尼诺:#内容到视图的构造器,但滚动在CSS定义的.library。所以一旦我改变了我的DOM从

so the error was pretty simple in the end... I was passing "el: #content" to the view's contructor, but the scroll was defined in CSS on ".library". So once I changed my DOM from

<div id="content">
  <div class="library">
  </div>
</div>

<div id="content" class="library"></div>

一切工作正常...

everything worked properly...

推荐答案

这code为我工作:

var View = Backbone.View.extend({
  events: { "scroll": "scroll" },
  scroll: function(){ console.log( "scrolling..." ); }
});

检查的jsfiddle

由于@JoshLeitzel说,我认为这个问题是在DOM元素它的自我。

As @JoshLeitzel said I think the issue is in the DOM element it self.

尝试旁路骨干做的:

$("#content").bind( "scroll", function(){ console.log( "scrolling from jquery directly" ); } );

也尝试更换:

el: $('#content')

el: '#content'

我不认为这是问题,但定义的新风格:)

这篇关于捕获的div滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆