weixin_33736649 2015-03-12 16:38 采纳率: 0%
浏览 15

WordPress博客-jQuery问题

I have built a pretty simple WordPress blog however nearing the final stages I have run into a small problem that I cannot figure out for the life of me!

The site is http://lincsbusiness.co/, its running an ajax request so when you get the the bottom on the page its calls the next issues from the next page. Pretty simple.

However, if you follow these step you will be able to see the problem that I am talking about.

  1. Refresh the home page
  2. Expand the first issue, so you can see the sub headlines
  3. Scroll to the bottom and till you get to issue 12
  4. Try and expand that, and you will notice that the expansion bounces.

I am using the jQuery call back feature so after the AJAX request has finished it allows the jQuery to keep working.

And to stop having duplicate piece of jQuery for one before the event and one after, I have given the first four issue in the list unique identifiers, which are different to the one in the callback.

Here is the code I am using

jQuery(document.body).on('click', '.before-load', function(event) {
    jQuery(this).closest('.thepost').find('.thepost-entry').slideToggle('slow');
});

And I use another piece, which is identical but just uses the '.after-load' class, just so I can separate them.

If you can replicate the issue and see whats going on, and have a potential fix. that would seriously save me my sanity.

Thanks

  • 写回答

1条回答 默认 最新

  • weixin_33721427 2015-03-12 16:45
    关注

    I have a feeling this is because you are re-adding the listener for the click each time you expand the page, so probably every time you load more posts, the next post you click bounces +1 times.

    I'd recommend stopping any other jQuery execution, removing the 'click' handler, then letting the ajax call expand the page...and then re-adding the 'click' handler to each post.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)