【发布时间】:2012-01-17 00:01:40
【问题描述】:
我有一个脚本可以创建带有一些背景图像的 div,然后移动它们,它在所有其他浏览器上运行良好,但 chrome 太滞后了。我检查了我的代码,发现当我删除以下代码时,它在 chrome 上也很好用。
//imageCount = count of image placed for animation, this loop gets source of
//each image, create divs, then makes each image to background of a div
for(imageNum=0;imageNum<imageCount;imageNum++)
{
var imageSrc= $("#image img:eq("+imageNum+")").attr("src");
//save image sources for later use
images.push(imageSrc);
//creating divs
$("#main_cont").append("<div name=img"+imageNum+" class=img_cont></div>");
//here is my problem
//when i delete .css part works great
$("#main_cont .img_cont:eq("+imageNum+")").width(tWidth).height(tHeight).css({
backgroundImage: "url("+imageSrc+")",
backgroundRepeat: "no-repeat",
backgroundSize: tWidth +"px "+ tHeight +"px "
});
//this part is not about my question, each div's position for animation
var offset = $("#main_cont .img_cont:eq("+imageNum+")").offset();
yPos.push(offset.top);
xPos.push(offset.left);
}
我在 jsfiddle 上的代码的简单版本:http://jsfiddle.net/uUj4h/2/(可能需要一点时间来加载大图像的原因)
如果我找不到解决方案,我将在 div 中使用图像而不是背景,但对于我的动画,但我需要 div。
【问题讨论】:
标签: jquery css google-chrome animation html