0
나는이 스노우 애니메이션을하고 있으며 일부 브라우저에서는 FPS를 반으로 줄이기 위해 돔을 절반 만 움직여야합니다. 각 조각에 대해 복제/애니메이션을 적용한 후에 변수를 설정해야합니다.jQuery 복제/애니메이션 전에 변수를 초기화하는 방법
"i"변수가 일반이기 때문에 복제 전에 변수를 설정할 수 없으며 각 조각에 대해 찌꺼기가 늘어날수록 찌름 범위 내에서 설정해야하기 때문에 복제 전에 변수를 설정할 수 없습니다. 기능 (약속 애니메이션)
호출하는 함수는 애니메이션이 시작할 때 :
$flake.clone().appendTo('#snowContainer').css({
left: x,
top: y,
opacity: startOpacity,
width: sizeFlake + '%',
*** I need to initialize the "i" variable here,
or somewhere before the loop "step" starts ***
color: options.flakeColor
}).stop().animate({'border-spacing': 0 },{
step: function(p, fx) {
angle += 0.01;
xadd = (Math.sin(angle) + (sizeFlake/4) * 1.5)/speed;
yadd = (Math.cos(angle) + (sizeFlake/2)/2)/speed;
x += xadd;
y += yadd;
*** if "i" variable here is not defined it throws an error ***
if(i%2==0)
{
var move = {top: y + "px", left: x + "px"};
$(fx.elem).css(move);
}
i++;
}, duration: 20000, easing:"linear", complete: function(){ $(this).remove(); //console.log("flake deleted");
}
});
[JSFiddle] (http://jsfiddle.net/)과 같이 실행되는 코드의 미리보기를 만들 수 있습니까? 코드를 수정하면 도움이됩니다. – Turnerj