AngularJS窗口滚动事件不会触发
我知道有一些关于这个问题的类似问题,但我没有一个解决方案可以帮助我。
I know there are some similar question concerning this problem, however I none of the solutions could help me.
我正在使用AngularJS并希望检测滚动事件。我尝试了很多关于如何获取事件的版本,但是最多只有在第一次加载时才会触发,然后再也没有。
I am using AngularJS and want to detect the scroll event. I tried plenty of versions on how to get the event, however at most it fires when first loaded then never again.
我尝试过的最后一个代码如下:
My last code I tried was the following:
$($window).on('scroll', alert('scrolled'));
但我也试过这个:
- Jquery .on('scroll')not not not在滚动时触发事件
- 或只是简单的JQuery .scroll()事件
- window.onscroll = function(ev)。 ..
等等,但没有任何作用。
and many more, but nothing works.
任何人都可以告诉我我做错了什么?
Can anyone tell my what I am doing wrong?
更新:我尝试了指令的东西,这对safari BUT完全没问题但是没有使用chrome。怎么回事?
Update: I tried the directive stuff, this works perfectly fine with safari BUT however not with chrome. Whats going on?
Update2:使用shift键时,它适用于chrome移动视图。铬到苹果触控板有什么限制吗? WTF?
Update2: It works with the chrome mobile view when using the shift key. Are there any restrictions on chrome to apple trackpad? WTF?
我只会使用
$(window).scroll(function () { alert('scrolled') })
或者你可以使用
angular.element($window).bind("scroll", function(e) {
alert('scrolled')
})