2014-09-18 2 views
0

난과 같이 왼쪽의 값을 변경할 수있는 속성을 설정 :속도 JS 동적

$.Velocity.animate(element, 
    { left: '100%' }, 0 
); 

을하지만 어떻게, 변수 동적으로 이런 일을 그 속성을 변경할 수 있습니다.

var side = 'left'; 

$.Velocity.animate(element, 
    properties[side] = '100%', 0 
); 

그런 다음 측면을 오른쪽 또는 왼쪽으로 동적으로 설정할 수 있습니다.

+0

'애니메이션이 실행 중일 때'를 '동적으로 설정'하여? –

+0

아니요, 애니메이션 전에는 기본적으로 화면의 어느면에서 움직이는지를 결정할 수 있습니다. 전체 애니메이션에는 바운스 효과가 있습니다. – wazzaday

+1

'velocity.animate()'는'jQuery.animate()'의 드롭 인 대체물이므로 동일한 규칙이 적용된다고 가정합니다. http://stackoverflow.com/questions/14693113/passing-variables-to- jquery-animate – mechalynx

답변

2
var props = {left: '100%'}; 
$.Velocity.animate(element, 
    props, 0 
); 

// later just change props: 
props = {right: '50%'}; 
// next animation runs with the new value 
$.Velocity.animate(element, 
    props, 0 
);