Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <h1 class="text-center">Pomodoro Timer</h1>
  <div class="small text-center">
    <a href="https://en.wikipedia.org/wiki/Pomodoro_Technique" target="_blank">What is a "Pomodoro Timer"?</a>
  </div>

  <main>
    <div class="container">
      <div class="invisible col-xs-2"></div>
      <div class="col-xs-8">
        <div class="row">
          <div class="invisible col-xs-2"></div>
          <div class="col-xs-3 lengthBox">
            <h3>Break Length</h3>
            <div class="row">
            <div id="break-minus" class="col-xs-2 minusTime">-</div>
            <div id="break-time" class="col-xs-8"></div>
            <div id="break-plus" class="col-xs-2 addTime">+</div>
            </div>
          </div>
          <div class="invisible col-xs-2"></div>
          <div class="col-xs-3 lengthBox">
            <h3>Session Length</h3>
<div class="row">
            <div id="session-minus" class="col-xs-2 minusTime">-</div>
            <div id="session-time" class="col-xs-8"></div>
            <div id="session-plus" class="col-xs-2 addTime">+</div>
            </div>
          </div>
        </div>
        <div class="text-center">
          TIMER
          <div id="timer-circle">
            <div id="countdown">
            <div id="countdown-title">Session</div>
              <div id="countdown-control"><span class='glyphicon glyphicon-play'></span></div>
            <div id="countdown-time"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>
  <footer>
    <div class="container text-center">
      made by <a href="//codepen.io/kode29" target="_blank">Kyle M. Perkins</a>
    </div>

  </footer>
</div>
              
            
!

CSS

              
                body{
   font-family: "Comfortaa", cursive;
  background-color: #1e1f21;
  color: #cac9cd;
}
main{
  margin: auto;
}
main h3{
  text-align: center;
  text-transform: uppercase;
  font-size: 80%;
}
#timer-circle{
  margin: 20px auto;
  width: 50%;
  height: 50%;
}
#countdown{
  font-size: 4em;
  position: relative;
  top: 100px;
  margin-bottom: -58%;
  cursor: pointer;
  transistion: all .5s ease-in-out;
}
.lengthBox{
  font-size: 2em;
  text-align: center;
}
.lengthBox .addTime, .lengthBox .minusTime{
  cursor: pointer;
}
.lengthBox .addTime:hover, .lengthBox .minusTime:hover{
    color: #fff;
}
              
            
!

JS

              
                // progressbar.js@1.0.0 version is used
// Docs: http://progressbarjs.readthedocs.org/en/1.0.0/

var bar = new ProgressBar.Circle("#timer-circle", {
  strokeWidth: 6,
  easing: 'easeInOut',
  duration: 1400,
  color: '#39ff14',
  trailColor: '#eee',
  trailWidth: 1,
  svgStyle: null
});

// Initial setup
bar.animate(1.0);  // Number from 0.0 to 1.0

var currentStatus = "paused";
var sessionTotal = "1500"; //25 min by default
var breakTotal = "300"; // 5 min by default
var timerTick, timerTotal;
var countdownTimer;
var currentTimer = "session";
var soundSessionEnd = "https://notificationsounds.com/soundfiles/c75b6f114c23a4d7ea11331e7c00e73c/file-sounds-1090-good-things-happen.mp3";
var soundBreakEnd = "https://notificationsounds.com/soundfiles/97e8527feaf77a97fc38f34216141515/file-sounds-1084-consequence.mp3";
var soundSession = new Audio(soundBreakEnd);
var soundBreak = new Audio(soundSessionEnd);

function timeConvert(num) {  
  var minutes = num / 60;
  var rminutes = Math.floor(minutes);
  var seconds = (minutes - rminutes) * 60;
    var rseconds = Math.round(seconds);
    if (rseconds.toString().length == 1)
      rseconds = "0"+rseconds;
  return rminutes+":"+rseconds;
}

$(function(){
  
  // Initial setup
  $('#session-time').html(timeConvert(sessionTotal));
  $('#break-time').html(timeConvert(breakTotal));
  $('#countdown-time').html(timeConvert(sessionTotal));
  
  $("#countdown").on('click', function(){
    if (currentStatus == "paused"){
      $('#countdown-control span').removeClass("glyphicon-play").addClass("glyphicon-pause");
      currentStatus = "play";
    } else{
      $('#countdown-control span').removeClass("glyphicon-pause").addClass("glyphicon-play");
      currentStatus = "paused";
    }
    runCountdown();
  });
  
    function runCountdown(){
      timerTotal = (currentTimer == "session") ? sessionTotal : breakTotal;
      timerTick = timerTotal;
    if (currentStatus == "play"){
      countdown();
    } else{
      clearInterval(countdownTimer);
    }
  }

  function countdown(){
    // display time left
    timerTick--;
    console.log(timerTick);

    $('#countdown-time').text(timeConvert(timerTick));
    // animate the circle
    bar.animate(timerTick/timerTotal);
    if (timerTick >= 0)
      countdownTimer = setTimeout(countdown, 1000);
    else
      playSound();
  }
 
  
  
  
  function playSound(){
 var path = document.querySelector('#timer-circle > svg > path:last-child');
    
    if (currentTimer == "session"){
      console.log("Break Time!");
			soundBreak.play();
      currentTimer = "break";
      timerTotal = breakTotal;
      $('#countdown-title').html("Break!");
      path.setAttribute("stroke", "#189ad3");
      //bar.stroke = "#c00";
    } else {
      console.log("Back to work!");
      soundSession.play();
      currentTimer = "session";
      timerTotal = sessionTotal;
      $('#countdown-title').html("Session");
      path.setAttribute("stroke", "#39ff14");
      //bar.stroke = "#39ff14";
    }
    console.log("Timer: "+timerTotal+" | Tick: "+timerTick);
    runCountdown();
  }
  
  function updateTimer(){
    var total;
    if (currentTimer == "session")
      total = sessionTotal;
    else
      total = breakTotal;
    $('#countdown-time').html(timeConvert(total));
  }
  
  $('#break-minus').on('click', function(){
    breakTotal = (breakTotal * 1) - 60;
    if (breakTotal <= 0)
      breakTotal = 60;
    $('#break-time').html(timeConvert(breakTotal));
    updateTimer();
  });
   $('#break-plus').on('click', function(){
    breakTotal = (breakTotal * 1) + 60; // To make sure we're adding numbers
    $('#break-time').html(timeConvert(breakTotal));
     updateTimer();
  });
    $('#session-minus').on('click', function(){
    sessionTotal = (sessionTotal * 1) - 60;
    if (sessionTotal <= 0)
      sessionTotal = 60;
    $('#session-time').html(timeConvert(sessionTotal));
      updateTimer();
  });
   $('#session-plus').on('click', function(){
    sessionTotal = (sessionTotal * 1) + 60; // To make sure we're adding numbers
    $('#session-time').html(timeConvert(sessionTotal));
     updateTimer();
  });
  
  
});
              
            
!
999px

Console