无法使用jQuery委派滚动事件 [英] Can't delegate scroll event using jQuery

查看:69
本文介绍了无法使用jQuery委派滚动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery在特定类别的元素上滚动触发事件,例如:

I'm trying to use jQuery to fire an event on scroll on a particular class of elements, like so:

$('body').on('scroll', '.overflow', function() { do stuff; });

但是,do stuff永远不会发生.我做了一些实验,似乎滚动事件无法使用.on委派. (有关测试案例,请参见 http://jsbin.com/aJeDiru/2 ).

However, do stuff never happens. I've done a little experimentation, and it looks as though the scroll event can't be delegated using .on. (see http://jsbin.com/aJeDiru/2 for a test case).

有没有办法让我委托它?还是有一个很好的理由™,为什么永远不应该以这种方式设置它来进行委托?

Is there a way that I can get it to delegate? Or is there a Very Good Reason™ why it should never be set up to delegate in this fashion?

推荐答案

根据由于事件委托依赖于事件的发生,该事件冒泡到附加了处理程序的元素上,因此您将无法使用委托.

Since event delegation relies on the event bubbling to the element you've attached the handler to, you won't be able to use delegation.

这篇关于无法使用jQuery委派滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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