骨干滚动事件未触发

时间:2012-11-20 19:42:19

标签: jquery backbone.js backbone-events

骨干滚动事件不会触发。 click事件和jquery附加滚动工作。这也是一个小提琴:http://jsfiddle.net/cX2UV/

JS

var TView = Backbone.View.extend({        
    events: {
        'scroll .content': 'loadMore',
        'click .code': 'codeClick'
    },

    loadMore: function() {
        this.$el.append('<p>backbone scrolling</p>');
    },

    codeClick: function() {
        this.$el.append('<p>clicking</p>');
    }
});

new TView({ el: '.target' });

$('.content').scroll(function(){ $('.target').append('jq scrolling...'); });

HTML

<div class="target">
<div class="content">
    <div>
        <span class="text">text</span>
        <span class="term">termmm</span>
        <span class="codes"><span class="code">12345</span></span>
    </div>
    <div>
        <span class="text">text</span>
        <span class="term">termmm</span>
        <span class="codes"><span class="code">12345</span></span>
    </div>  
</div>
</div>

CSS

body {margin:1em;}
.content {background:#EEE; height: 200px; overflow: scroll;}
.code{color:#00c}

1 个答案:

答案 0 :(得分:8)

使用选择器将事件绑定到视图时Backbone使用jQuery的delegate。正如an answer to this question中所述,scroll事件doesn't bubble up因此处理程序无法响应它。