I am trying to attach a couple scroll events to the new UI.body.events. I want to have the scroll events fired at all times on all routes but only be assigned once, so I figured this would be the right place to assign them.

Taken from: https://github.com/meteor/meteor/wiki/Using-Blaze#uibody-is-now-a-template-corresponding-to-the-entire-body-element

UI.body.events({
  'click': function () {
    alert("clicked somewhere on the page");
  }
});

This should be obvious probably, but my question is where do I insert this bit of code in my app? You would think anywhere, but I tried it in main.js, as its own UI.js file in my client/helpers/ folder, inside a rendered template callback, but it seems it never fires.

有帮助吗?

解决方案

Hmm, interesting. UI.body.events is supposedly not implemented yet, so I'm surprised it works for Keith Nicholas. Apparently, it's coming in version 0.8.1, but you just have to use jQuery to bind events to document.body for the time being.

其他提示

Works for me, I just copy pasted it into a js file in my client folder I'm currently working on and it instantly started working.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top