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
精彩评论