SorenRomer SorenRomer - 22 days ago 7
Javascript Question

Javascript function parameter won't load

I'm animating an svg file, and in order not to bloat my code I have written the follow function:

function animateSingleAtt(svgName, element, attToAnimate, attValue, animationTiming) {
svgName.select( element ).animate({
attToAnimate : attValue
}, animationTiming);
}


All parameters are loaded just fine, except for attToAnimate. I have no clue as to why this is – it is just passed to the svg element as an attribute named 'attToAnimate'.

I have tried logging it outside of the animate-function, and when I do that, it's passed just fine.

Any help will be greatly appreciated!

Answer

It looks like you are using attToAnimate as a key on an object. To do this properly, change the code to something like this:

function animateSingleAtt(svgName, element, attToAnimate, attValue, animationTiming) {
  var anObject = {};
  anObject[attToAnimate] = attValue;
  svgName.select( element ).animate(anObject, animationTiming);
}

This should properly build the object you want to pass to .animate