无法通过在特定div上滚动来触发jquery函数 [英] Can't trigger a jquery function with scroll on a particular div

查看:72
本文介绍了无法通过在特定div上滚动来触发jquery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(document).on(click,。Container,function( ){bb 








$ b pre $ $(document).on(scroll,。Container,function(){})

长版本:
对不起,但发布代码片段并不可行,因为它是一个复杂的类似应用程序的界面,但我会尝试将问题解释为我的能力最好:


  • 手机响应式网站根据屏幕空间不同加载不同的界面。

  • 最小的界面由三部分组成 - 顶部导航,底部搜索和中间内容。

  • 内容大多在使用时加载,而不是在页面加载时加载。 li>
  • 我需要在内容滚动的时候触发一个函数,既可以上下滚动,也可以不停地飞过某个点。

  • 我仍然可以滚动,它不会作为事件触发。

  • 我试过了我发现的一切都无济于事,从我的短暂经历和我一直在阅读的内容来看,我认为它可能与滚动不像点击一样起泡一样,但我不知道我应该做什么或尝试使用这些信息。

  • 虽然它看起来不会影响我的问题(删除它并不能解决问题),但我应该透露我正在使用hammer.js来模拟触摸因为它可能会影响解决方案。



感谢您提供所有帮助。



除此之外,我将使用无效的建议进行编辑 -

解决方案

在@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆