why doesn#39;t delegate work for scroll?(为什么不委托滚动工作?)
问题描述
我正在尝试使用 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
这篇关于为什么不委托滚动工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么不委托滚动工作?


基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01