質問

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