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.

    评论

    报告相同问题?

    悬赏问题

    • ¥100 r语言多元回归模型怎么看表达式
    • ¥15 PMM 9010/30P
    • ¥15 pom文件依赖管理,未找到依赖
    • ¥15 现在后端返回给我一堆下载地址,都是一个视频切片后的,如何在uniapp安卓环境下将这些分片的视频下周并且合并成原始视频并下载到本地。
    • ¥15 Unity导出2D项目运行时图片变成马赛克
    • ¥15 关于communitytoolkit.mvvm的生成器得到的代码看起来没有被使用的问题
    • ¥15 matlab中此类型的变量不支持使用点进行索引
    • ¥15 咨询第六届工业互联网数据创新大赛原始数据
    • ¥15 Pycharm无法自动补全,识别第三方库函数接收的参数!
    • ¥15 STM32U575 pwm和DMA输出的波形少一段