javascript - 在滚动事件中使用 Jquery
问题描述
滚动页面时,我无法在 console.log 中显示文本。
$("#idOfUl").on('scroll', function() {
console.log('Event Fired');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="idOfUl">
<ul>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
</ul>
</div>
滚动页面时,我无法在 console.log 中显示文本。
滚动页面时,我无法在 console.log 中显示文本。
滚动页面时,我无法在 console.log 中显示文本。
滚动页面时,我无法在 console.log 中显示文本。
滚动页面时,我无法在 console.log 中显示文本。
解决方案
该元素需要是可滚动的(带有 的固定高度overflow:scroll
)。
$("#idOfUl").scroll(function() {
console.log('Event Fired');
});
#idOfUl {
height: 100vh;
overflow: scroll;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="idOfUl">
<ul>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
<li>
You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow
property when you want to have better control of the layout. The default value is visible. You can use the overflow property when you want to have better control of the layout. The default value is visible. You can use the overflow property when
you want to have better control of the layout. The default value is visible.
</li>
</ul>
</div>
推荐阅读
- python - 如何编辑这个文件?
- html - 在我使用 CanvasJS、HTML 和 Angular 调整浏览器窗口大小之前,条形图不会显示
- android - 安卓 | ANR - 如何检测?
- class - Vue中一个条件绑定多个类
- android - 从多平台 kotlin 项目访问 C/C++ 库
- python - 在python中更改用户权限
- javascript - 如何将谷歌搜索链接添加到 html 中的每个单词并具有性能?
- python - 使用 python 请求发送带有 unicode 数据的 http post 请求
- java - 从 Java 以 DataStore 模式连接到 Cloud Firestore
- javascript - 如何将产品价格移动到添加到购物车按钮旁边