title: Pausing Javascript animation on minimize
body: <p>I am using the <code>Chart.js</code> library for my animated graphs on the website. From reading other discussions on the subject, browsers treat <code>SetInterval()</code> code differently when a tab is inactive or minimized.</p>
  
  <p>I noticed one suggestion stating that stopping the animation and restarting it when the tab regains focus should correct the issue. I am not sure how to do this nor can I find any code. The library has <code>"animation: true"</code> where I believe this can be used to stop/start it, but not sure how to implement it.</p>
  
  <pre><code>setInterval(function()
  {
      $.ajax({
          type: "POST",
          url: "&lt;?= $data['baseUrl']; ?&gt;" +  "graphs.json",
          data: { 'action': 'getServerStats' },
          dataType: 'json',
          success: function(data)
          {
              ram = data['result']['RAMUsageMB'];
  
              // Add two random numbers for each dataset
              ramGraph.addData([ram], '');
  
              // Remove the first point so we dont just add values forever
              ramGraph.removeData();
          }
      });
  }, 1000);
  </code></pre>