Hi,
I'm currently attempting to make a scroll event in a plugin,
what would be the best way to implement a scroll event into Adapts backbone model?
I'm currently using
Hi,
I'm currently attempting to make a scroll event in a plugin,
what would be the best way to implement a scroll event into Adapts backbone model?
I'm currently using
I'd generally just crib from an existing plugin... which one depends on why exactly you want to do as a result of the scroll event - but the bookmarking extension might be a good place to start looking?
FYI in the example code you supply you're running _.bindAll
on a function ('detect_scroll') that isn't shown... and your $(window).scroll
is attached to a function (this.onScroll
) that isn't shown either. I'm wondering if your code should look more like this:
initialize: function() {
$(window).scroll(this.onScroll.bind(this));
},
But without seeing those functions it's hard to know for sure...
Hi Matt,
Thanks for the quick response.
I've manged to get the scroll function to work, thanks for your help.
for future reference, I ended up attaching it to the prerender like this.
preRender: function () {
$(window).scroll(this.onScroll.bind(this));
},
I then added the function alongside the rest of the code
onScroll:function(){
//code goes here
}
Cool, glad I could be of help.
Just be aware - running code on 'scroll' can be hugely detrimental to performance. You should seriously consider using either _.throttle or _.debounce to restrict the amount of times your onScroll
function executes.