1
for (var i = 0; i < items.length; i++) {
  //items[i].style.left = items[i].basicLeft + 100 * phase[i] + 'px';
  //console.log(items[i].style.left);
  var translation=items[i].basicLeft + 100 * phase[i] + 'px';
  console.log(translation);
  items[i].style.transform = 'translateX(translation)';
}

Here the translateX is not updating I tried using constants in place of variable as an argument to translateX but there are no changes.

console.log for translation gives expected values.

If I use style.left the code which I have commented above the code works fine.

akarsh gowda
  • 29
  • 2
  • 4
  • Title is wrong: it should read `object.style.transform`, not `object.style.transition`! – Zoli Szabó Sep 20 '16 at 18:09
  • What if you do this: `items[i].style.transform = 'translateX(' + translation+ ')';` – Asons Sep 20 '16 at 18:09
  • Apparently, you have a typo in your code, it should be `items[i].style.transform`, not `items[i].transform`. – Zoli Szabó Sep 20 '16 at 18:10
  • How should JavaScript know that `translation` in `'translateX(translation)'` should be replaced with the value of a variable? – Felix Kling Sep 20 '16 at 18:14
  • @FelixKling Interpolation is great, but in this case, is it really a duplicate? ... maybe concatenate variable with string would be more appropriate? ... as in this post: http://stackoverflow.com/questions/4234533/how-do-i-concatenate-a-string-with-a-variable – Asons Sep 20 '16 at 18:26
  • @LGSon: I see "interpolation" is just a general term for "how can I insert a variable into this string", which is what the OP wants to do here, even if they didn't express it. Whether that happens through string concatenation or other means doesn't matter. I wasn't able to find a question that proposes string concatenation as an answer, but string concatenation is at least mentioned in the question itself. The question you linked to seems to be fine as well. – Felix Kling Sep 20 '16 at 18:29

0 Answers0