jquery.on滚动不起作用

编程入门 行业动态 更新时间:2024-10-28 16:18:35
本文介绍了jquery.on滚动不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试构建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滚动不起作用

本文发布于:2023-11-03 01:02:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553858.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!