2012-07-06 2 views
0

내 backbone.js보기에 scroll 이벤트가 있습니다. 그러나 화면을 스크롤하면 scroll 이벤트 핸들러가 시작되지 않습니다. $(windows).scroll() 잘 작동하지만. 이는 scroll 이벤트를보기에 사용할 수 없다는 것을 의미합니까?뷰가 실행되지 않는 스크롤 이벤트 (backbone.js)

VIEW 또한

PhotoListView = Backbone.View.extend({ 
    el: '#photo_list', 

    events: { 
     'scroll': function() { 
      console.log('scrolling!'); 
     } 
    }, 

    initialize: function() { 
     this.collection.bind('reset', this.render, this); 
    }, 

    render: function() { 
     // ... 
     }, this); 
     return this; 
    } 
}); 

, 내가 삽입해야 backbone.js 코드의 어느 부분에서 스크롤 이벤트를 처리 할 $(windows).scroll()을 사용하려면? 아래는 현재 내가있는 장소입니다. 이 해당 요소에 바인딩 된 이후 해당 요소 "#photo_list"를 스크롤 할 때

라우터

var AppRouter = Backbone.Router.extend({ 
    routes: { 
     '': 'explore' 
    }, 

    explore: function() { 
     this.photoList = new PhotoCollection(); 
     var self = this; 
     this.photoList.fetch({ 
      success: function() { 
       self.photoListView = new PhotoListView({ collection: self.photoList }); 
       self.photoListView.render(); 

       // Check for Scrolling 
       $(window).scroll(function() { 
        self.checkScroll(); 
       }); 
      } 
     }); 
    }, 

    checkScroll: function() { 
     var contentOffset = $('#photo_list').offset().top; 
     var contentHeight = $('#photo_list').height(); 
     var pageHeight = $(window).height(); 
     var scrollTop = $(window).scrollTop(); 
     var triggerPoint = 100; 

     if(contentOffset + contentHeight - scrollTop - pageHeight < triggerPoint) { 

      this.photoListView.collection.requestNextPage() 
       .done(function(data, textStatus, jqXHR) { 
      }); 

     } 
    } 

}); 

var app = new AppRouter(); 
Backbone.history.start(); 
+0

스크롤 핸들러는 요소 "#photo_list"를 스크롤하면 해당 요소에 바인딩되므로 스크롤 할 수 있습니까? – Esailija

+0

오,'# photo_list' 요소는 스크롤바가 없습니다. 위의 코드에서와 같이 라우터에서'$ (window) .scroll()'을 사용해야 할 것 같습니까? – Nyxynyx

+0

예,'$ (window) .scroll'은 윈도우를 스크롤 할 때 사용합니다 ...'$ (element) .scroll'은 그 요소를 스크롤 할 때 사용합니다. – Esailija

답변

1

스크롤 핸들러가 실행됩니다.

$(window).scroll은 창을 스크롤 할 때 사용됩니다.

관련 문제