문제

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