0

can we make Angular2 @HostListener listen to "window"? not to window or document event, because I want to make smooth animation based on event but not waiting value from event..

@HostListener('window', ['$event'])
  alwaysListeningAlwaysUnderstanding() {
console.log("I'm listening..");
}

So the problem is, I want to make an animation based on scroll position, like scrollme plugin, but I don't want use it since scrollme use jquery.

For now I already create @HostListener function based on 'window:scroll' but the return value not smooth if I scroll it fast, its like 2,45,123,432. and it give impact to my animation, some element not render nicely and oftenly giving a bad result.

So is there a way to fix it? I thought listening to scroll position without waiting scroll to move make it more smooth.

user5436320
  • 133
  • 2
  • 17
  • Sorry but I dont understand "listen to "window"? not to window " what are you asking ? – Vova Bilyachat Sep 18 '17 at 06:26
  • You will have to filter all that events any way to do related actions, why not accept that you have to write many event listeners one for each event you are interested in? – Vega Sep 18 '17 at 06:27
  • 1
    `window` is not an event and doesn't emit anything. What exactly do you want to listen to? How is that related to animation? – Günter Zöchbauer Sep 18 '17 at 06:27
  • I want to make animation based on scroll, but getting scroll value not give a smooth animation since there's a delay for getting scroll value. – user5436320 Sep 18 '17 at 06:28
  • @VolodymyrBilyachat not to window event.., so i need something that keep listening my function – user5436320 Sep 18 '17 at 06:55
  • @Vega the problem is when i use window:scroll, the value not return smooth – user5436320 Sep 18 '17 at 06:56
  • @GünterZöchbauer maybe that's what i'm asking, i need some event that keep listening.. – user5436320 Sep 18 '17 at 06:57
  • Listening for what? What do you want to get notified about? – Günter Zöchbauer Sep 18 '17 at 07:06
  • @GünterZöchbauer i need some function that keep listening my function, maybe some async function – user5436320 Sep 18 '17 at 07:09
  • Can you please add some more concrete information :D What does listening to a function mean? What function, what does it do, what's it's purpose? – Günter Zöchbauer Sep 18 '17 at 07:31
  • I think it would be better if you reformulate your question to explain what you are trying to achieve instead of what you think would be the solution to resolve it :) – Vega Sep 18 '17 at 07:40
  • @GünterZöchbauer Thanks for telling me, I already fix the question more specific to what I want to achieved :D – user5436320 Sep 18 '17 at 09:12
  • @Vega Thanks for telling me, I already fix the question more specific to what I want to achieved :D – user5436320 Sep 18 '17 at 09:14
  • 2
    https://stackoverflow.com/questions/37315781/prevent-a-native-browser-event-like-scroll-from-firing-change-detection/37318618#37318618 or https://stackoverflow.com/questions/43108155/angular-2-how-to-keep-event-from-triggering-digest-loop/43294113#43294113 might help – Günter Zöchbauer Sep 18 '17 at 09:19

0 Answers0