为什么不委托滚动工作?
我正在尝试使用 jquery 委托绑定到滚动事件.
I am trying to use jquery delegate to bind to scroll events.
html
<div id='parent'>
<div id='child'>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </div>
</div>
css
#parent {
width:200px;
height:200px;
border:2px solid black;
overflow:auto;
}
#child {
width:300px;
height:300px;
background:red;
}
javascript
$('#parent').delegate('#child', 'scroll', function(){
alert(this)
})
jsfiddle
http://jsfiddle.net/C6DRR/1/
为什么它不起作用?
推荐答案
我认为这可能会绑定你的滚动
i think this may bind your scroll
$('#child').live('keyup', function() {
var el = $(this);
if (!el.data("has-scroll")) {
el.data("has-scroll", true);
el.scroll(function(){
//doscrollaction(el);
});
}
doscrollaction(el);
});
按操作要求:
我更改了 css,因此子溢出并使用 jquery.scroll 并且有效,但是没有像 jquery 那样的滚动"事件,我不知道,因此 bin,live 等不能设置为滚动,以及为什么您的代理不起作用
i change the css so child overflows and use jquery.scroll and that works, however there is no 'scroll' event like you have for jquery not that i know of anyway, hence the reason why bin, live etc can not be set for scroll and also why your deligate will not work
相关文章