title: How do I get the opacity to stop fading with a button press?
body: <p>Currently I have the opacity of lines decreasing by 3% every 400ms. I want this feature to continue, but I also want to create a button press function where once the user presses the button, the fading stops and the opacity at which the fading stops can get recorded. Thank you so much!</p>
  
  <pre><code>const step = 0.03
  
  // Helper function to extract the stimulus elements
  const getLines = () =&gt; 
    ['one', 'two', 'five', 'fourteen', 'fifteen']
      .map(id =&gt; document.getElementById(id))
  
  getLines().forEach(line =&gt; line.style.opacity = 1);
  
  // Setup event handler
  var timer = undefined;
  function decreaseOpacity() {
    getLines().forEach(line =&gt; {
          line.style.opacity -= step
          console.log(line.style.opacity);
    });
    timer = setTimeout(() =&gt; {
      decreaseOpacity();
    }, 400);
  }
  decreaseOpacity();
  </code></pre>