我有一张幻灯片,为每张图片制作10张切片,并为切片制作动画。即,歌剧,铬运行动画,但在Firefox中,动画太慢,我尝试了不同的电脑,仍然是相同的。我用一个“for”循环创建切片,创建10个新的div,每个div具有不同的背景位置属性。我如何解决这个Firefox的?谢谢。火狐上的jquery动画速度
我已经添加了一些代码
//part of creating slices
for(imageN=0;imageN<imageCount;imageN++)
{
$('#image').append("<div name=slices class=slices></div>");
slicesCreate(imageN);
}
//#image is main div contains slice divs.
//Here is sliceCreate function
/*In this function, it takes how many images added to slideshow, takes all
sources for each image and creates slices*/
function slicesCreate(imageN)
{
var i = 0;
var nleft = 0;
var image= $("#image img:eq("+imageN+")").attr("src");
for(i=0;i<10;i++)
{
$('.slices:eq('+imageN+')').append("<div name=slice"+i+" class=slice></div>");
$(".slices:eq("+imageN+") .slice[name=slice"+i+"]").css({
backgroundImage: "url("+image+")",
backgroundPosition: nleft + "px 0px",
backgroundRepeat: "no-repeat",
backgroundSize: twidth
});
/*sliceCount is a global variable that calculated when page loaded for display
resolution*/
nleft -=sliceCount;
}
}
/* And here is one of the animation code, this code runs for every slice */
function animateSlices(current,next,slice,animid,delay)
{
setTimeout(function() {
$(".slices:eq("+next+") .slice[name=slice"+slice+"]").css({
display: "block",
marginTop: "-700px"
});
$(".slices:eq("+next+") .slice[name=slice"+slice+"]").animate({
marginTop: "0px"
},1000);
$(".slices:eq("+current+") .slice[name=slice"+slice+"]").animate({
marginTop: "700px"
},1000);
}, delay);
}
当您单击动画按钮
function anim()
{
if(!animating)
{
animating = true;
var j = 0;
var delay = 0;
current = $('.slices:visible').index('.slices');
var siz = $('.slices').size();
var cSize = $('.slices:visible').size();
var txen = 2;
var rand = parseInt(Math.random()*3);
var last = $('.slices:last').index('.slices');
if(cSize>1)
return;
//this part is calculating id of next image
if(siz > 1 && current!= last)
{
txen = current + 1;
}
else if(siz == 1)
{
txen = current;
}
else if(siz > 1 && current== last)
{
txen = 0;
}
//this part is makin next image slices visible and changes z-index for animation
$(".slices:eq("+txen+")").css({
display: "block",
zIndex: "92"
});
$(".slices:eq("+current+")").css({
zIndex: "91"
});
//this part calls animateSlices function for every next image slices
for(j=0;j<10;j++)
{
$(".slices:eq("+txen+") .slice[name=slice"+j+"]").css({
marginTop: "0px"
});
animateSlices(current,txen,j,rand,delay);
/*current = this image, txen = next image, j = slice number, rand = animation id,
delay = delay for animation */
if(rand==0)
delay += 150;
else
delay += 50;
}
}
else
return;
}
编辑调用该函数:我已经改变了“marginTop”到“顶”,在动画和对于每个切片来说,绝对的位置,现在解决的问题,它不再滞后。我可能有一些关于使用jquery代码定位div的错误,或者改变很多margin可能是一些滞后的原因,但正如我所说,它只发生在firefox中,即opera或chrome。不知道是什么造成了滞后问题,但是当我解决这个问题时,我会在这里写下我的解决方案。现在我将改变marginTop的最高价值。感谢大家的答案。
为什么不使用http://api.jquery.com/animate/? –
你的动画代码是怎样的?一个例子真的有助于理解这个问题。 –
您将在每个浏览器中体验不同的动画速度。在IE 7中看看你的动画,然后看看你认为FF的速度有多慢。无论如何,你需要粘贴你的动画代码,因为你的描述你的方法听起来很奇怪,我做了很多jquery动画。 –