123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <h1>PomodoroTimer</h1>

<div id="control-panel">
  <table align="center">
    <tr>
      <td>BREAK LENGTH</td>
      <td>SESSION LENGTH</td>
    </tr>
    <tr>
      <td><button onclick="breakMinus()">-</button> <span id="break-length">3</span> <button onclick="breakPlus()">+</button></td>
      <td><button onclick="sessionMinus()">-</button> <span id="session-length">7</span> <button onclick="sessionPlus()">+</button></td>
    </tr>
  </table>
</div>
<div id="pomodoro" onclick="toggleTimer()">
  <div class="pomoinner">
  <p id="title">Session</p>
  <p id="timer">7</p>
  <span id="fill"></span>
</div>
</div>
<div id="reset">
  <p><button onclick="reset()">RESET</button></p>
</div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Pacifico|Open+Sans:300);

body {
  width: 600px;
  margin: 0px auto;
  text-align: center;
  background-color: rgb(51,51,51);
  color: white;
  font-family: 'Open Sans', Arial;
}

h1 {
  font-family: 'Pacifico';
  font-size: 5em;
}

div {
  margin: 0px auto;
}

#control-panel {
  width: 400px;
  margin: -30px auto 20px auto;
}

table td {
  padding-left: 30px;
  font-size: 0.9em
}
table td:first-child {
  padding-left: 0px;
  padding-right: 30px;
  text-align: right;
}

table span {
  padding: 22px;
  font-size: 2.6em;
}

#pomodoro {
  width: 300px;
  height: 300px;
  border-radius: 50%;
  border: 3px solid green;
  line-height: 55px;
  font-size: 3.3em;
  box-sizing: border-box;
  
}

.pomoinner{
   width: 294px;
  height: 294px;
  padding: 10px;
  border-radius: 50%;
  border: 4px solid rgb(51,51,51);
  box-sizing: border-box;
  position: relative;
  overflow-x: hidden;
  overflow-y: hidden;
}


#fill {
  bottom: 0px;
  left: 0px;
  position: absolute;
  width: 300px;
  background-color: rgb(255, 68, 68);
  z-index: -1;
}

#control-panel button {
  vertical-align: top;
  line-height: 2.0em;
  border: none;
  padding: 0;
  font-size: 1.6em;
  cursor: pointer;
  color: white;
  outline: none;

  background-color: rgb(51,51,51);

}


#reset {
  margin-top: 50px;
  font-size: 0.3em;
}

#reset button {
  background-color: rgb(51,51,51);
  color: white;
  padding: 6px;
}


            
          
!
            
              // Initialisation
var breakLength = 300;
var sessionLength = 1500;
var clockTime = sessionLength;
var timerPaused = true;
var onBreak = false;

// Setters / Getters
function setBreakLength(newLength){
  breakLength = (newLength <= 0) ? 0 : newLength;
  notify();
}

function setSessionLength(newLength){
  sessionLength = (newLength <= 0) ? 0 : newLength;
  notify();
}

function setClockTime(secs){
  clockTime = secs;
  notify();
}

function getClockTime(){
  return clockTime;
}

// Timer
var intervalTimer;

function toggleTimer(){
  timerPaused = !timerPaused;
  !timerPaused ? startTimer() : stopTimer();
}

function startTimer(){
   notify();
   intervalTimer = setInterval(tick, 1000)
}

function stopTimer(){
  clearInterval(intervalTimer);
}

function tick(){    
      if (getClockTime() <= 0) {
          stopTimer();
          toggleBreak();
          return;
      }     
      setClockTime(getClockTime() - 1)      
}

function toggleBreak(){
     onBreak = !onBreak;
     setClockTime(onBreak ? breakLength : sessionLength);
     startTimer();
}

/*
  Controls
*/

function breakMinus(){incrementBreakLength(-60);}
function breakPlus(){incrementBreakLength(60);}
function sessionMinus(){incrementSessionLength(-60);}
function sessionPlus(){incrementSessionLength(60);}

function reset(){
  stopTimer();
  timerPaused = true;
  onBreak = false;
  setClockTime(sessionLength);
};


// Increment break length. If on break, and timer paused, reset clock to new length. 
function incrementBreakLength(increment){
  setBreakLength(breakLength + increment);
  if (timerPaused && onBreak) {
    clockSeconds = 0;
    setClockTime(breakLength);
  } 
}

// Increment session length. If in session, and timer paused, reset clock to new length. 
function incrementSessionLength(increment){
    setSessionLength(sessionLength + increment);
    if (timerPaused && !onBreak) {
      clockSeconds = 0;
      setClockTime(sessionLength);
    } 
}

/*
  Update View Function
*/
var notify = (function(){
  var prevBreakLength;
  var prevSessionLength;
  
  return function(){
    // Just always update clock.
    document.getElementById('timer').innerHTML = formatClockDisplay();
    document.getElementById('title').innerHTML = onBreak ? 'Break' : 'Session';    
    document.getElementById('fill').style.backgroundColor = onBreak ? 'red' : 'green';
    document.getElementById('fill').style.height = fillHeight();
    
    // Update Break Length
    if (prevBreakLength !== breakLength) {
      document.getElementById('break-length').innerHTML = breakLength / 60;      
       prevBreakLength = breakLength;
    }
    
    // Update Session Length
    if (prevSessionLength !== sessionLength)       {
      document.getElementById('session-length').innerHTML = sessionLength / 60;
      prevSessionLength = sessionLength;
    }   
  }
  
})();
/*
  Helpers
*/
function formatClockDisplay(){
  var time = getClockTime();
  var mins = Math.floor(time / 60);
  var secs = clockTime % 60;
  secs = secs < 10 ? '0' + secs : secs;
  return (timerPaused && time === sessionLength) ? mins : mins + ':' + secs; 
}

function fillHeight(){
  return 286 - ((getClockTime() / (onBreak ? breakLength : sessionLength)) * 286) + 'px';
}

// init view;
notify();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console