开发者

Show AJAX content after images have loaded

I am developing my own lightbox kind of jquery plugin. Everything works but I want to hide the loaded content until the images have loaded in the browser from the AJAX call. I found a similar post and I am using the following script but the setTimeout function is what reveals the content and not the .load function. Am I trying to achieve the impossible?

$.ajax({
      url: 'meet/'+ pLoad + '.html',  
      success: function(data) {
        var imageCount = $(data).filter('img').length;
        var imagesLoaded = 0;
        $(data).hide()
         .appendTo('#zoom_inner')
         .开发者_如何学运维filter('img')
         .load( function() {
          ++imagesLoaded;
          if (imagesLoaded >= imageCount) {
          $('#zoom_inner').children().show();
          }
          });
        setTimeout( function() { $('#zoom_inner').children().show() }, 5000 );
       }
    });


Regarding your comments:

data is just a string in your success callback - it's "html", but it's a string.

make it a node to use:

var $images = $(data); // i.e. turn <div><img /></div> into a div with an img as a child or whatever you got
var imageCount = $images.find('img').length;

cool, eh?


If you investigate this article I think you can find solution for your problem (http://jqueryfordesigners.com/image-loading/)

Best wishes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜