cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="container-fluid">
  <div id="title" class="text-center">
    <h1>Pomodoro Clock</h1>
    <p>By <a href="https://codepen.io/aaronyoung/">Aaron Young</a>
  </div> <!-- title -->
  
  <div class="text-center">
    <button id="clock" type="button" class="btn btn-default">
      <span id="status">Session</span>
      </br></br>
      <span id="clock-time">25</span>
    </button>
  </div>  <!-- clock -->
  
  <div class="row">
    <div class="col-xs-6">
      <table id="break" class="time-table">
        <tr>
          <td colspan="6"><h3 class="text-center">Break Time</h3></td>
        </tr>
        <tr>
          <td><button id="break-minus" type="button" class="btn btn-default plus-minus">-</button></td>
          <td><span id="break-length">5</span></td> 
          <td><button id="break-plus" type="button" class="btn btn-default plus-minus">+</button></td>
        </tr>
      </table>     
    </div> <!-- Break time -->
    
    <div class="col-xs-6">
      <table class="time-table">
        <tr>
          <td colspan="3"><h3 class="text-center">Session Time</h3></td>
        </tr>
        <tr>
          <td><button id="session-minus" type="button" class="btn btn-default plus-minus">-</button></td>
          <td><span id="session-length">25</span></td> 
          <td><button id="session-plus" type="button" class="btn btn-default plus-minus">+</button></td>
        </tr>
      </table>        
    </div> <!-- Session Time -->
    
    <div class="text-center">
      <button id="reset" type="button" class="btn btn-danger">Reset</button>
    </div> <!-- Reset -->
  
  </div> <!-- Options container -->
</div>

<!-- audio -->
<audio id="alarm">
  <source src="https://cs.oberlin.edu/~syoung/audio/alarm_ring.mp3" type="audio/mpeg">
</audio>

<audio id="ticking">
  <source src="https://cs.oberlin.edu/~syoung/audio/alarm_tick.mp3" type="audio/mpeg">
</audio>
            
          
!
            
              body {
  background: grey;
}

button {
  outline-style: none !important;
  font-weight: 200;
}

h1, h3, p {
  color: white;
  font-weight: 200;
}

span {
  font-weight: 200;
}

a {
  color: #6EC6CF;
  text-decoration: none !important;
  font-weight: 200;
}

#clock {
  height: 213px;
  width: 213px;
  border-radius: 50%;
  font-size: 150%;
  background: white;
}

td {
    height: 50px; 
    width:50px;
}

.time-table td {
  text-align:center; 
  vertical-align:middle;
}

.plus-minus {
  border-radius: 50%;
}

#break {
  float: right;
}

#reset {
  width: 50%;
  margin-top: 10px;
}

            
          
!
            
              var breakTime = 5;
var sessionTime = 25;
var Break = false;
var sessionTimeSec = 25 * 60;
var sessionBase = 25 * 60;
var pause = true;
var counter = setInterval(timer, 1000);

$(document).ready(function(){
  $("#break-minus").on("click", subBreakTime);
  $("#break-plus").on("click", addBreakTime);
  $("#session-minus").on("click", subSessionTime);
  $("#session-plus").on("click", addSessionTime);
  $("#clock").on("click", timerClicked);
  $("#reset").on("click", resetClock);
});

function subBreakTime() {
  if (breakTime > 0) {
    breakTime--;
    $("#break-length").html(breakTime);
  }
  if (Break) {
    sessionTimeSec = breakTime * 60;
    sessionBase = breakTime * 60;
  }
}

function addBreakTime() {
  if (breakTime < 60) {
    breakTime++;
    $("#break-length").html(breakTime);
  }
  if (Break) {
    sessionTimeSec = breakTime * 60;
    sessionBase = breakTime * 60;
  }
}

function subSessionTime() {
  if (sessionTime > 0) {
    sessionTime--;
    $("#session-length").html(sessionTime);
  }
  if (!Break) {
    sessionTimeSec = sessionTime * 60;
    sessionBase = sessionTime * 60;
    $("#clock-time").html(sessionTime);
  }
}

function addSessionTime() {
  if (sessionTime < 60) {
    sessionTime++;
    $("#session-length").html(sessionTime);
  }
  if (!Break) {
    sessionTimeSec = sessionTime * 60;
    sessionBase = sessionTime * 60;
    $("#clock-time").html(sessionTime);
  }
}

function timerClicked() {
  if (pause) {
    $("#ticking")[0].play();
    pause = false;
  } else {
    pause = true;
  }
}

// http://stackoverflow.com/questions/1191865/code-for-a-simple-javascript-countdown-timer
function timer() {
  if (sessionTimeSec <= 0) {
     clearInterval(sessionTimeSec);
     //counter ended, do something here
     timesUp();
  } else if (!pause) {
    sessionTimeSec=sessionTimeSec-1;
    displayRemainingTime(sessionTimeSec);
  }
}

function displayRemainingTime(time) {
  var mins = Math.floor(time/60);
  time -= Math.floor(time/60) * 60;
  if (mins < 10) {
    mins = "0" + mins;
  }
  var sec = time;
  if (time < 10) {
    sec = "0" + sec;
  }
  $("#clock-time").html(mins + ":" + sec);
  
  // display progress
  var remaining = sessionTimeSec/sessionBase;
  if (remaining > 0.9) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 100%, #6EC6CF 0%)");
  } else if (remaining > 0.8) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 90%, #6EC6CF 10%)");
  } else if (remaining > 0.7) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 80%, #6EC6CF 20%)");
  } else if (remaining > 0.6) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 70%, #6EC6CF 30%)");
  } else if (remaining > 0.5) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 60%, #6EC6CF 40%)");
  } else if (remaining > 0.4) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 50%, #6EC6CF 50%)");
  } else if (remaining > 0.3) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 40%, #6EC6CF 40%)");
  } else if (remaining > 0.2) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 30%, #6EC6CF 30%)");
  } else if (remaining > 0.1) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 20%, #6EC6CF 20%)");
  } else if (remaining > 0) {
    $("#clock").css("background", "linear-gradient(210deg, #FFF 0%, #6EC6CF 0%)");
  }
}

function timesUp() {
  $("#alarm")[0].play();
  $("#clock").css("background", "white");
  if (Break) {
    $("#status").html("Session");
    resetClock();
  } else {
    // time for break
    $("#status").html("Break");
    Break = true;
    sessionTimeSec = breakTime * 60;
    sessionBase = breakTime * 60;
    $("#clock-time").html(breakTime);
  }
}

function resetClock() {
  sessionTimeSec = sessionTime * 60;
  sessionBase = sessionTime * 60;
  pause = true;
  Break = false;
  $("#status").html("Session");
  $("#clock-time").html(sessionTime);
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console