저는 각 이미지에 대해 10 개의 슬라이스를 만들고 해당 슬라이스에 애니메이션을 적용하는 슬라이드 쇼를 가지고 있습니다. 즉, 오페라, 크롬은 애니메이션을 잘 실행하지만 파이어 폭스에서는 애니메이션이 너무 느리고 다른 컴퓨터로 시도해 보았습니다. 10 개의 새 div를 만들고 각 div는 다른 배경 위치 속성을 갖는 "for"루프로 슬라이스를 만듭니다. 파이어 폭스를 어떻게 해결할 수 있습니까? 감사.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를 배치하거나 동일한 마진을 많이 변경하면 지연이 발생할 수 있습니다.하지만 필자는 오페라 또는 크롬이 아닌 파이어 폭스에서만 발생한다고 말한 바 있습니다. 그 지연 문제를 일으키는 원인을 모르지만 내가 이것을 해결할 때 여기서 나의 해결책을 쓸 것이다. 지금은 marginTop의 최고 가치를 변경할 것입니다. 답변 해 주셔서 감사합니다. 다른 사용자가 이전에 발견으로
http://api.jquery.com/animate/를 사용하지 않는 이유는 무엇입니까? –
애니메이션 코드는 어떻게 생겼습니까?예를 들어 실제로 문제를 이해하는 데 도움이됩니다. –
당신은 모든 브라우저에서 다른 애니메이션 속도를 경험하게 될 것입니다. IE 7에서 애니메이션을보고 FF가 얼마나 느린 지 확인하십시오. 어쨌든, 귀하의 설명에 따라 애니메이션 코드를 붙여 넣어야합니다. 귀하의 메서드가 이상하게 들리며 많은 jquery 애니메이션을 수행합니다. –