I know there are some similar question concerning this problem, however I none of the solutions could help me.
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'));
But I also tried this:
and many more, but nothing works.
Can anyone tell my what I am doing wrong?
Update: I tried the directive stuff, this works perfectly fine with safari BUT however not with chrome. Whats going on?
Update2: It works with the chrome mobile view when using the shift key. Are there any restrictions on chrome to apple trackpad? WTF?
I would just use
$(window).scroll(function () { alert('scrolled') })
OR you could use
angular.element($window).bind("scroll", function(e) {
alert('scrolled')
})
不需要angular.element()向控制器注入$ window,使用window.onscroll事件
$window.onscroll = function (){ console.log('window was scrolled!'); };
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.