AngularJS窗口滚动事件不会触发 [英] AngularJS window scroll event does not fire

查看:327
本文介绍了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'));

但我也试过这个:

等等,但没有任何作用。

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')
})

这篇关于AngularJS窗口滚动事件不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆