无法通过在特定div上滚动来触发jquery函数 [英] Can't trigger a jquery function with scroll on a particular div
问题描述
$(document).on(click,。Container,function( ){bb
$ b pre $ $(document).on(scroll,。Container,function(){})
长版本:
对不起,但发布代码片段并不可行,因为它是一个复杂的类似应用程序的界面,但我会尝试将问题解释为我的能力最好:
感谢您提供所有帮助。
除此之外,我将使用无效的建议进行编辑 -
在@A 。沃尔夫和@ M.Doye我发现了一些可行的方法。虽然它无助于理解至少它的工作有什么问题。
document.addEventListener('scroll',function(event ){
if(event.target.className ==='Container'){
insert magic spell here
}
},true);
Short version: This works
$(document).on("click",".Container",function(){})
This does not:
$(document).on("scroll",".Container",function(){})
Long version: I'm sorry but posting a code snippet isn't feasible as it's a complex app-like interface but I'll try to explain the issue to the best of my abilities:
- Mobile responsive website that loads different interfaces depending on screen real-estate.
- Smallest interface composed of 3 parts - navigation at the top, search at the bottom and content in the middle.
- Content is mostly loaded during use and not at page load.
- I need to trigger a function when the content is scrolled, both up and down and on the fly not just past a certain point.
- I can still scroll, it just doesn't trigger as an event.
- I've tried everything I've found to no avail, from my short experience and what I've been reading I think it might have to do with how scroll doesn't bubble up the same as click, but I have no idea what I should do or try with that information.
- While it doesn't seem to influence my problem (removing it doesn't solve the issue) I should disclose that I'm using hammer.js to simulate touch events as it might influence the solution.
Thanks in advance for all the help.
Beyond this point I'll edit with suggestions that didn't work--
With help from @A. Wolf and @M.Doye I found something that works. While it doesn't help understand what was wrong at least its working.
document.addEventListener('scroll',function(event){
if(event.target.className==='Container'){
insert magic spell here
}
},true);
这篇关于无法通过在特定div上滚动来触发jquery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!