jQuery检测包含元素上的滚动 [英] Jquery detect scroll on included element
问题描述
我有一个文件结构,其中index.php头包含我的JS文件和JQ.索引文件中的内容加载了一个php include标签,以加载wall.php,这是因为动态性太强了.
I have a file structure where index.php head includes my JS file and JQ. The content in the index file is loaded with a php include tag to load wall.php due too some dynamic.
在wall.php中,我有一个ID为'wrapper'的div,我想检测该div中的滚动事件,但是它似乎没有触发.
In wall.php i have a div with the id 'wrapper', I would like to detect scroll events in that div, however it doesn't seem to trigger.
这是我的JQ
$(document).on('scroll', '#wrapper', function() {
alert('test');
});
(我有文件准备功能-其他JQ作品)
(I have det document ready function - other JQ works)
有人知道为什么吗?
推荐答案
除非将css属性溢出设置为scroll,并且div容器实际上是可滚动的,否则它将不会检测到滚动.我在JSFiddle上做了一个小实现.
It will not detect the scroll unless the css property overflow is set to scroll, and the div container is actually scrollable. I made a small implementation on JSFiddle.
CSS
#wrapper{
height: 200px;
overflow: scroll;
}
jQuery
$('#wrapper').on('scroll', function(){
alert("Scroll Detected");
});
只有当div变小时,它才可滚动并可以检测到滚动.
Only when the div becomes to small, it will then become scrollable and scroll can then be detected.
这篇关于jQuery检测包含元素上的滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!