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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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 id="container">
  <h1 class="title">Pomodoro Clock app</h1>
  <div id="sessionControls" class="controls">
    <a href="#" id="sessionPlus" class="btn plusButton"><span>+</span></a>
    <span class="title">Session</span>
    <span id="sessionTitle" class="title">1 minutes</span>
    <a href="#" id="sessionMinus" class="btn minusButton"><span>-</span></a>
  </div><!-- end session controls div -->
  <div id="sessionTimer" class="timer">
    <div id="mainCircle">
      <!-- Ordinarily the height/width would be set in CSS, but for some reason the JS ignores that height in the draw function, so we set it here. -->
      <canvas height="305px" width="305px" id="circleCanvas"></canvas>
    </div>
  </div> <!-- end sessionTimer div -->
  <div id="breakControls" class="controls">
    <a href="#" id="breakPlus" class="btn plusButton"><span>+</span></a>
    <span class="title">Break</span>
    <span id="breakTitle" class="title">5 minutes</span>
    <a href="#" id="breakMinus" class="btn minusButton"><span>-</span></a>
  </div><!-- end break controls div -->
</div>

              
            
!

CSS

              
                body {
  background-color: #e7e3e2;
}

#container {
  width: 500px;
  margin-top: 10%;
  margin-left: auto;
  margin-right: auto;
}

.controls {
  float: left;
  height: 200px;
  width: 85px;
  margin-top: 75px;
}

.title {
  display: block;
  margin-top: 5px;
  text-align: center;
  font-weight: bold;
}

.btn {
  display: inline-block;
  height: 40px;
  width: 45px;
  margin: 5px 21px 5px;
  
  /* Border-radius is set to round off the corners on each button */
  -webkit-border-radius: 8px;
  -moz-border-radius: 8px;
  border-radius: 6px;
  
  /* Box shadow adds the 3D effect of a pressable button */
  /* This section controls the size and color of the 3D effect on each button */
  -webkit-box-shadow: 0 4px 0 #8c8c8c, 0 15px 20px rgba(0, 0, 0, .25);
  -moz-box-shadow: 0 4px 0 #8c8c8c, 0 15px 20px rgba(0, 0, 0, .25);
  box-shadow: 0 4x 0 #8c8c8c, 0 15px 20px rgba(0, 0, 0, .25);
}

.btn:active {
  -webkit-box-shadow: 0 4px 0 #8c8c8c, 0 12px 10px rgba(0, 0, 0, .2);
  -moz-box-shadow: 0 4px 0 #8c8c8c, 0 12px 10px rgba(0, 0, 0, .2);
  box-shadow: 0 4px 0 #8c8c8c, 0 12px 10px rgba(0, 0, 0, .2);
}

.btn span {
  display: inline-block;
  height: 33px;
  width: 45px;
  margin-left: -13px;
  padding-top: 2px;
  background-color: #595959;
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#595959), to(#6d6d6d));
  background: -moz-linear-gradient(#595959, #595959);
  font-weight: bold;
  font-size: 16pt;
  color: white;
  
  /* Border radius inside the span rounds off the edges of the spans */
  -webkit-border-radius: 8px;
  -moz-border-radius: 8px;
  border-radius: 6px;
}

.btn:active span {
  /* Transform lines make each button look like it moves up and down when it is pressed */
  -webkit-transform: translate(0, 2px);
  -moz-transform: translate(0, 2px);
  -o-transform: translate(0, 2px);
  transform: translate(0, 2px);
}

.timer {
  float: left;
  width: 302px;
}

#currentSession {
  margin-top: 60px;
  margin-left: auto;
  margin-right: auto;
  width: 180px;
  font-size: 32pt;
  color: white;
}

#currentTime {
  margin-top: 60px;
  margin-left: auto;
  margin-right: auto;
  width: 120px;
  font-size: 32pt;
  color: white;
}

              
            
!

JS

              
                // Set up the timer variables.
var onBreak = false;
var onTheClock = false;
var timerInterval = null;

// Set up the canvas variables.
var canvas = document.getElementById("circleCanvas");
var context = canvas.getContext("2d");
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 150;

// Set up the fill variables.
var fillAmount = 0;
var fillIncrease = 0;
var startingMinutes = (onBreak) ? parseInt($("#breakTitle").text().split(" ")):parseInt($("#sessionTitle").text().split(" "));
var timerAmount = new Date();
timerAmount.setMinutes(startingMinutes);
timerAmount.setSeconds(0);

// This function uses the HTML canvas to draw the timer and all of the things in it.
function drawTimer() {
  context.save();
  
  // Draw the initial circle.
  context.beginPath();
  context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  context.fillStyle = "#595959";
  context.fill();
  
  // Clip a rectangle inside the circle that will get "filled in" over time.
  context.clip();
  context.fillStyle = (onBreak) ? "red":"green";
  context.fillRect(centerX - radius, centerY + radius, radius * 2, -fillAmount);
  context.restore();
  
  // Draw the border around the timer.
  context.beginPath();
  context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  context.lineWidth = 5;
  context.strokeStyle = (onBreak) ? "red":"green";
  context.stroke();
  context.restore();
  
  // Clip a text box to display either "Session" or "Break".
  context.clip();
  context.font = "bold 32pt Helvetica";
  context.fillStyle = "white";
  context.textAlign = "center";
  var textToFill = (onBreak) ? "Break":"Session";
  context.fillText(textToFill,150,120,200);
  context.restore();
  
  // Clip another text box to display the time left on the timer.
  context.clip();
  context.font = "bold 32pt Helvetica";
  context.fillStyle = "white";
  context.textAlign = "center";
  context.fillText(timerAmount.getMinutes() + ":" + ("0" + timerAmount.getSeconds()).slice(-2),150,210,200);
  context.restore();
}

// This function fills up the circle and decreases the time on the timer.
function pomodoroTimer() {
  drawTimer();
  
  // If we've filled up the circle, switch between session and break.
  if (fillAmount === radius * 2) {
    onBreak = !onBreak;
    fillAmount = 0;
    resetTimer();
  }
  
  // Increase the fill amount.
  // Determine how fast to increment the progress timer based on the number of minutes defined.
  // The height of the timer is 300px, which makes it easier to divide up minutes (multiples of 60).
  startingMinutes = (onBreak) ? parseInt($("#breakTitle").text().split(" ")):parseInt($("#sessionTitle").text().split(" "));
  fillIncrease = 300 / (startingMinutes * 60);
  //var fillIncrease = 10;

  fillAmount += fillIncrease;
  
  // Decrease the timer.
  timerAmount.setSeconds(timerAmount.getSeconds() - 1);
}

// This function resets the fill and timer variables when the amount of time changes.
function resetTimer() {
  var newTime = (onBreak) ? parseInt($("#breakTitle").text().split(" ")):parseInt($("#sessionTitle").text().split(" "));
  
  timerAmount.setMinutes(newTime);
  timerAmount.setSeconds(0);
  fillAmount = 0;
  
  drawTimer();
}

$(document).ready(function() {
  // Draw the initial timer.
  drawTimer();

  $("#sessionPlus").on("click", function() {
    // Get the current time on the timer (separated by a space) and increment it by one.
    // Make sure the timer is stopped before updating the current time on the timer 
    var newTime = parseInt($("#sessionTitle").text().split(" ")) + 1;
    
    // Before changing anything...
    // Make sure the clock is not currently active.
    // Make sure we are not on a break.
    if (!onTheClock & !onBreak) {
      $("#sessionTitle").text(newTime + " minutes");
      resetTimer(newTime);
    }
  });
  
  $("#sessionMinus").on("click", function() {
    // Get the current time on the timer (separated by a space) and increment it by one.
    // Make sure the timer is stopped before updating the current time on the timer (LATER).
    var newTime = parseInt($("#sessionTitle").text().split(" ")) - 1;
    
    // Before changing anything...
    // Make sure the timer does not go below zero.
    // Make sure the clock is not currently active.
    // Make sure we are not on a break.
    if (newTime > 0 && !onTheClock && !onBreak) {
      $("#sessionTitle").text(newTime + " minutes");
      resetTimer(newTime);
//      drawTimer();
    }
  });
  
  $("#breakPlus").on("click", function() {
    // Get the current time on the timer (separated by a space) and increment it by one.
    // Make sure the timer is stopped before updating the current time on the timer (LATER).
    var newTime = parseInt($("#breakTitle").text().split(" ")) + 1;
    
    // Before changing anything...
    // Make sure the clock is not currently active.
    if (!onTheClock) {
      $("#breakTitle").text(newTime + " minutes");
      
      // Only update the fill and timer variables if we are actually on a break.
      if (onBreak) {
        resetTimer(newTime);
      }
    }
  });
  
  $("#breakMinus").on("click", function() {
    var newTime = parseInt($("#breakTitle").text().split(" ")) - 1;
    
    // Before changing anything...
    // Make sure the timer does not go below zero.
    // Make sure the clock is not currently active.
    if (newTime > 0 && !onTheClock) {
      $("#breakTitle").text(newTime + " minutes");
      
      if (onBreak) {
        resetTimer(newTime);
      }
    }
  });
  
  // Logic for the start/stop button.
  $("#mainCircle").on("click", function() {
    if (!timerInterval) {
      onTheClock = true;
      
      // Start the timer.
      timerInterval = setInterval(pomodoroTimer, 1000);
    }
    else {
      onTheClock = false;
      
      // Stop the timer.
      clearInterval(timerInterval);
      timerInterval = null;
    }
  });
});


              
            
!
999px

Console