jQuery无限滚动导致链接暂时不起作用?
几周前我用 jquery 实现了一个无限滚动页面。滚动本身效果很好,但我得到了一个非常奇怪的副作用。
当我滚动并加载新内容时,在前几秒钟内所有链接都不起作用。事实上,页面上任何地方的链接都不会在几秒钟内起作用。如果我滚动得非常远,例如连续快速加载 5 个页面,情况似乎会变得更糟 - 然后我必须等待 20 秒才能单击页面上任何位置的任何链接。
我在使用 Firefox 或 IE8 时也有同样的经历,所以我猜这不是浏览器的问题。
有什么想法或解决办法吗?
A couple of weeks ago I implemented an infinite scrolling page with jquery. The scrolling itself works great, but I'm getting a very strange side effect.
When I scroll and the new content loads, none of the links work for the first few seconds. In fact, no links anywhere on the page work for a couple of seconds. And it seems to get worse if I scroll really really far, for instance loading 5 pages in quick succession - then I'll have to wait 20 seconds before any of the links anywhere on the page are clickable.
I'm having the same experience using Firefox or IE8, so I'm guessing it's not the browser.
Any ideas what the cause or fix is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
还有这个问题吗?
问题:
初步想法:
尝试使用 setTimeout。对于某些浏览器,jQuery 的 .scroll 会在滚动条发生变化的每个像素时调用处理函数...而不是在所有滚动完成后调用,这可能会导致函数调用过载。尝试这样的操作,当您滚动时它不会执行 1000 个函数调用(这只是一个简单的示例......代码可能会更好):
Still have this problem?
Questions:
Initial Thoughts:
Try using a setTimeout. For some browser jQuery's .scroll calls the handler function every pixel the scrollbar is changed... not once all the scrolling is done which can cause an overload of function call. Try something like this do that it doesn't do 1000 function calls when you scroll (this is just a quick example... code could be better):