I couldn\'t find a scroll event for meteor in the meteor docs. How do I go about doing something as someone scrolls the window down in a meteor application?
I\'ve tried
In Meteor there is no native template support for scroll events, so you have to do within your Template.name.onRendered
callback. However, you will get a memory leak if you don't remove it from Template.name.onDestroyed
. This is best accomplished with namespaced events, since something like $(window).off('scroll');
will detach all scroll events from window.
import { $ } from 'jquery';
Template.myTemplateName.onRendered(function(){
// You can do this multiple times
$(window).on('scroll.whateverNamespace', function() { ... });
$(window).on('scroll.whateverNamespace', function() { ... });
})
Template.myTemplateName.onDestroyed(function(){
$(window).off('scroll.whateverNamespace');
})