我有一个物品清单。它们中的每一个都是一个带有名称的方块,当用户将鼠标悬停在方块上时,会显示一个图像,这是由 jQuery 完成的。代码是这样的:
$('.square').hover(function() {
var link = $(this).attr('title');
$(this).addClass('squarehover')
.css({backgroundImage: 'url(images/' + escape(link) + '.jpg)'});
}, function() {
$(this).removeClass('squarehover')
.attr('style', '');
});
.squarehover {
font-size: 0px;
background-repeat: no-repeat;
background-size: 100%;
-moz-background-size: 100%;
background-position: center center;
position: absolute;
z-index: 10;
cursor: pointer;
}
如果没有事先加载图片,悬停时会有一点延迟。另外,我不想在加载完所有图像后显示页面。
因为图像没有明确显示在页面中,是否可以先加载页面然后开始将图像加载到用户的缓存中(我的想法是用户不会立即将鼠标移动到这些方块上)?如果<img>HTML 中没有标签怎么办?
顺便说一句,既然background-sizeIE8不支持,如何处理?