我正在尝试构建DOM事件记录器,以便可以回放用户与页面的交互方式.我想使用jquery.on功能,以便可以记录页面上的所有事件.在这种特殊情况下,我试图记录滚动事件,但最终我想记录各种事件.
I am trying to build a DOM event recorder so I can play back how a user interacted with a page. I would like to use the jquery.on functionality so I can record all events on page. In this particular instance I am trying to record scroll events but eventually I want to record all sorts of events.
这是我的JS小提琴的链接.我希望用户滚动div后,文本"Hello"会变为"Bye".
Here is a link to my JS Fiddle. I expect the text "Hello" to change to "Bye" after a user scrolls the div.
jsfiddle/MnpPM/
Here是html
Herel is the html
<div id="parent" style="height: 300px; width: 300px; overflow: scroll"> <div style="height: 500px; width: 500px"> Hello </div> </div>这里是javascript
and here the javascript
$(document).on('scroll', '*', function () { $(this).html('Bye') });推荐答案
scroll事件不会通过dom传播,因此不能与委托一起使用.
the scroll event does not propagate through dom, so you can't use with delegate.
如果要监听scroll事件,则需要直接将回调添加到元素:
if you want to listen to the scroll event you need to add the callback direct to the element:
$(function() { $("#parent").on('scroll', function () { $(this).html('Bye') }); });更多推荐
jquery.on滚动不起作用
发布评论