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 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.

Quick-add: + add another resource

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.

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
Loading ..................

Console