title: Assigning translateY value by a string
body: <p>I'm using some JavaScript to keep my sidebar fixed when user scrolls the page and when he reached to nearly bottom of the page, then make the sidebar <code>position: static</code>. This is the code:</p>
  
  <pre><code>&lt;script&gt;
  
      window.onscroll = function() {
  var px = window.scrollY;
  var x = document.getElementsByClassName("sidebar");
  var body = document.body,
      html = document.documentElement;
  var poht = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
  var poht2 = poht - 1300;
  
  if(px &lt; poht2){
  
    if(px &gt; 1700)    
        {x[0].style.position="fixed";x[0].style.transform="translateY(-1700px)";}
  
    if(px &lt; 1680){
         if(x[0].style.position=="fixed")   
           {x[0].style.position="static";x[0].style.transform="translateY(20px)";}
     }
  }
         // Problem occurs here
  
  pos2 = -1 * 2300 - poht2;
  pos2 = pos2 + "px";
  
  else {x[0].style.position="static";x[0].style.transform="translateY(pos2)";}
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>At the last line (I mean <code>else</code>) when I want to calculate a value and assign it to <code>translateY()</code>, it's not working. What is the right form for doing that?</p>
  
  <p>Thanks.</p>