开发者

Need help loading content via ajax

开发者 https://www.devze.com 2023-01-29 10:14 出处:网络
Consider the following script: $(\".workSnippet\").click(function () { //set variable portfolioCount based on index

Consider the following script:

  $(".workSnippet").click(function () {

    //set variable portfolioCount based on index

    portfolioCount = $(".workSni开发者_如何学Goppet").index(this);

    //load content based on portfolioCount

    $('#work #cycle' + portfolioCount).load("ajax-content/ajax-content.php #portfolioImage" + portfolioCount);

    // when loaded, run animation functions 

    $("#work").ajaxComplete(function(){

        //help required here

        setTimeout(invokeMultipleCycle, 200);

        showWork();

    });

On my page, there are multiple 'thumbnails' called .workSnippet. When you click one of these, I want it to load content via ajax. It selects what content to load in conjunction with the index function. I have this working absolutely fine.

The problem is, it's a little messy. When you click .workSnippet it runs an animation, however the high quality image loads slowly whilst the animation is taking place.

What I want to do:

  1. Wait for the ajax request to complete before loading the functions invokeMultipleCycle and showWork.

  2. Before the animation occurs, add an ajax loading animation absolutely positioned above .workContent.

Please bear in mind two things:

  1. There are multiple .workSnippets on the page.
  2. The content is not loaded in workSnippet, but another div called #work.

You will see I have already tried to attempt this uses the ajaxComplete function. However, it does not seem to work. Perhaps this is because the ajax request completes but the image still needs to 'load'?

Your help will be most appreciated.

Thanks,

Steve


Perhaps this is because the ajax request completes but the image still needs to 'load'?

Yes. You have to do the animation after the images load. I can't think of a way to do that off the top of my head; I think looking into something similar to document.ready() is the solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号