平铺一个异步加载图像 - 把一个之间和背景URL
题
有关有很多小缩略图图像的部位,我想使用的占位符的gif,而每个图像加载。这需要如以下代码:
$('.this_img').each(function(){
var $this_img = $(this);
var $this_src = $(this).find('.sliderImage:first').attr('src');
var img = new Image();
// wrap our new image in jQuery, then:
$(img)
// set minimum dimensions
.css({
'min-height': '35px',
'min-width': '40px'
})
// once the image has loaded, execute this code
.load(function () {
// set the image hidden by default
$(this).hide();
// with the holding div #loader, apply:
$this_img
// remove the loading class (so no background spinner),
.removeClass('loading')
// then insert our image
.prepend(this);
// fade our image in to create a nice effect
$(this).fadeIn();
})
// if there was an error loading the image, react accordingly
.error(function () {
// notify the user that the image could not be loaded
})
// *finally*, set the src attribute of the new image to our image
.attr('src', $this_src);
这工作得很好,在样式表中指定的占位符,但我希望能够平铺这些图像,如果他们太短或狭窄,背景CSS是做了明显的方式,但它不兼容异步图像加载,AFAIK。
我问题:强>是否有可用于瓦片的<img>
标签任何jQuery的(或CSS3)?
或可替换地,有一种方法可以做到图像的台异步装载,然后将其粘到背景的CSS属性?这听起来有点不可思议,但也许它的工作原理。
解决方案
您可以发表您的HTML标记结构?在盲目,否则,但你尝试modifyu包含div的background属性?
// your callback function
function () {
// set the image hidden by default
$(this).hide();
// with the holding div #loader, apply:
$this_img
// remove the loading class (so no background spinner),
.removeClass('loading')
// then insert our image
//.prepend(this)
的CSS( '背景', '透明的URL( “ '+ $ this_src +”')左上重复');
// fade our image in to create a nice effect
$(this).fadeIn();
}
不隶属于 StackOverflow