title: Css and js circle countdown progress
body: <p>I am looking to create a circle that gets filled in as the timer countsdown, so if the timer was set to refresh after 10 seconds and there is 5 seconds left, only half a circle will be filled.  The closer it gets to 100%, the more the circle is filled in.  I have the code showing a filled in circle which should not be 100% filled, and as the timer is counting down, the circle moves around what looks like a central circle.</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-js lang-js prettyprint-override"><code> var interval = null;
   var secondsInHour = 60 * 60;
   var secondsInMinute = 60;
  
   $('#refresh-rate-chooser').change(function() {
  
       if (interval) {
           clearInterval(interval);
       }
       var countdownSeconds = $(this).find("option:selected").val();
       var countdownSecondsOriginal = countdownSeconds;
       
       if (countdownSeconds &amp;&amp; countdownSeconds &gt; 0) {
  
           interval = setInterval(function() {
               countdownSeconds--;
               var latestCountdownSeconds = $(this).find("option:selected").val();
               var percent = (countdownSecondsOriginal - countdownSeconds) / countdownSecondsOriginal * 100;
      console.log("countdownSeconds " + countdownSeconds);
      if (percent == undefined) {
       percent = 0;
      }
      var deg = 360 * percent/100;
      if (percent &gt; 50) {
       $(".progress-circle").addClass('gt-50');
      }
               $(".progress-circle").find('.progress-circle-fill').css('transform','rotate('+ deg +'deg)');
       
               if (countdownSeconds == 0) {
                   var formElements = $('form').serialize();
  
                   if (window.location.href.indexOf("?") &lt; 0) {
                       window.location.href = encodeURI(window.location.href + "?refreshrate=" + copyCountdownSeconds + "&amp;" + formElements);
                   } else {
                       var currentHref = replaceUrlParam(window.location.href, "refreshrate", copyCountdownSeconds);
                       $('form input, form select').each(
                           function(index) {
                               var input = $(this);
                               currentHref = replaceUrlParam(currentHref, input.attr('name'), input.val());
                           }
                       );
                       window.location.href = currentHref;
                   }
               }
  
           }, 1000);
       } else {
  
  
       }
   });
   </code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.countdown-progress {
      content: "";
      position: relative;
      margin: 1em;
      background-color: #81CE97;
      overflow: hidden;
  }
  
  .progress-circle .progress-circle-fill {
      content: "";
      position: absolute;
      border-radius: 50%;
      -webkit-transform-origin: 50% 100%;
      -moz-transform-origin: 50% 100%;
      -ms-transform-origin: 50% 100%;
      transform-origin: 50% 100%;
      -webkit-transform: rotate(140deg);
      -moz-transform: rotate(140deg);
      -ms-transform: rotate(140deg);
      transform: rotate(140deg);
      width: 4em;
      height: 4em;
      background: #81CE97;
  }
  
  .gt-50 .progress-circle {
      clip: rect(0, 2em, 4em, 0);
  }
  
  .gt-50 .progress-circle .progress-circle-fill {
      clip: rect(0, 4em, 4em, 2em);
      background: #E5E5E5;
  }</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 id="refresh-rate"&gt;
      &lt;select id="refresh-rate-chooser" name="refreshRateChooser"&gt;
          &lt;option value="0" selected&gt;-&lt;/option&gt;
          &lt;option value="10"&gt;10 secs&lt;/option&gt;
          &lt;option value="30"&gt;30 secs&lt;/option&gt;
          &lt;option value="60"&gt;1 min&lt;/option&gt;
          &lt;option value="120"&gt;2 mins&lt;/option&gt;
          &lt;option value="300"&gt;5 mins&lt;/option&gt;
          &lt;option value="600"&gt;10 mins&lt;/option&gt;
      &lt;/select&gt;
      &lt;input type="hidden" id="refreshrate" name="refreshrate" value="0" /&gt;
      &lt;div id="countdown-progress"&gt;
          &lt;div class="progress-circle text-center"&gt;
              &lt;div class="progress-circle-fill" &gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
  
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I can't seem to workout which bit of the code is wrong. To test this, change the select option and then the circle will move. I had originally based this on a donut chart, which is probably why the calculations are not working.</p>