开发者

jquery "NOW" event?

开发者 https://www.devze.com 2022-12-16 10:17 出处:网络
i\'ve got a jquery image preview plugin that i use. i use it like this: $(\'a.preview\').live(\'mouseover\', function() {

i've got a jquery image preview plugin that i use. i use it like this:

$('a.preview').live('mouseover', function() {
    $(this).imgPreview({
          preloadImages:   'true',
    });
});

i want the imgPreview function to be executed after an jquery ajaxcall that will insert an image in the DOM. 开发者_StackOverflow中文版so i wanna execute it to preload the image.

any ideas?


On your success callback in the ajax call, execute the same preload on the data returned:

$.ajax({
        url: 'doop.php',
        type: 'POST',
        data: 'before=' + theold + '&after=' + thenew,
        success: function(data) {
          $('a.preview', data).imgPreview({
            preloadImages: 'true'
          });
        }
});

This executes the .imgPreview on every in the ajax response that just came back.


I use this little function.

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
};

Then you can just do $.preloadImages('/url/to/image.gif'), somewhere where you handle onDomReady stuff. That way when you do that ajax call, it will all be there cached in the browser

0

精彩评论

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

关注公众号