title: Maintaining a CSS translate3d position when swapping classes
body: <p>I have an infinite scrolling background image in a div as you can see in the below snippet.</p>
  
  <p>The idea behind this is that its a timeline that I can change the speed of, ie. Normal speed, Fast, Slow and even Reverse. Using javascript I can successfully change the "speed class" that I have on the div and the image will successfully update to the speed and direction that I wish it to go.</p>
  
  <p>However my issue is that when I'm changing class, I lose the relative translate3d position of the image, so as the class changes, the background image location gets reset and then the new animation starts.</p>
  
  <p>I've tried to address this a few ways purely from a css point of view, by trying a complete swap of classes, as well as running a single class full time and applying the selected animation as an additional class, however I am unable to figure out how to maintain the relative background position when the new class is applied.</p>
  
  <p>How can I maintain the background images location when I swap class so that it doesn't look like the image is jumping from one position to another?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.timeline_frame {
    width: 100%;
    min-width: 1500px;
    background-color: #444;
    height: 250px;
    left: 0;
    right: 0;
    margin: auto auto;
    position: relative;
  }
  
  .timeline {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    margin: auto auto;
    width: 1500px;
    height: 200px;
  }
  
  .timeline_container {
    width: 1500px;
    height: 200px;
    overflow: hidden;
    position: relative;
  }
  
  .timeline_background {
    background: url("https://www.aidanwardman.com/timeline-bg.png") repeat-x;
    background-color: rgba(0, 0, 0, 0.5);
    width: 3000px;
    height: 200px;
    vertical-align: bottom;
  }
  
  .timeline_speed_normal {
    animation: slide 20s linear infinite;
  }
  
  .timeline_speed_slow {
    animation: slide 40s linear infinite;
  }
  
  .timeline_speed_reverse {
    animation: slide-reverse 2s linear infinite;
  }
  
  @keyframes slide {
    0% {
      transform: translate3d(0, 0, 0);
    }
    100% {
      transform: translate3d(-1500px, 0, 0);
    }
  }
  
  @keyframes slide-reverse {
    0% {
      transform: translate3d(-1500px, 0, 0);
    }
    100% {
      transform: translate3d(0, 0, 0);
    }
  }
  
  .button_frame {
    left: 0;
    right: 0;
    margin: auto;
    width: 400px;
    padding: 20px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="button_frame"&gt;
    &lt;button id="forward-normal"&gt;Forward Normal&lt;/button&gt;
    &lt;button id="forward-slow"&gt;Forward Slow&lt;/button&gt;
    &lt;button id="reverse"&gt;Reverse&lt;/button&gt;
  &lt;/div&gt;
  &lt;div class="timeline_frame"&gt;
    &lt;div class="timeline"&gt;
      &lt;div class="timeline_container"&gt;
        &lt;div class="timeline_background timeline_speed_normal"&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
    $("#forward-normal").click(function() {
      $(".timeline_background").removeClass("timeline_speed_fast timeline_speed_slow timeline_speed_reverse").addClass("timeline_speed_normal");
    });
    $("#forward-slow").click(function() {
      $(".timeline_background").removeClass("timeline_speed_fast timeline_speed_normal timeline_speed_reverse").addClass("timeline_speed_slow");
    });
    $("#reverse").click(function() {
      $(".timeline_background").removeClass("timeline_speed_fast timeline_speed_slow timeline_speed_normal").addClass("timeline_speed_reverse");
    });
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>