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.

            
              <link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">

<h1>Pomodoro Clock</h1>
<p class="directions col-to-row"><span>1. Set Session Length</span><span>2. Set Break Length</span><span>3. Click on the Clock to Begin!</span></p>

<div class="clock-wrapper col-to-row align-center justify-center">
  <div id="session" class="adjuster col">
    <h3>Session Length</h3>
    <div class="length-adjuster">
      <span class="plus btn"><i class="fa fa-plus" aria-hidden="true"></i></span>
      <span class="count sessionCount">25</span>
      <span class="minus btn"><i class="fa fa-minus" aria-hidden="true"></i></span>
    </div>
  </div>
  
  <div id="break" class="adjuster col">
    <h3>Break Length</h3>
    <div class="length-adjuster">
      <span class="plus btn"><i class="fa fa-plus" aria-hidden="true"></i></span>
      <span class="count breakCount">5</span>
      <span class="minus btn"><i class="fa fa-minus" aria-hidden="true"></i></span>
    </div>
  </div>

  <div id="clock">
    <div class="progress col align-center justify-center">
      <div id="sessionClock" class="show-block">
        <h2>Session</h2>
        <div class="countdown">
          <span class="hours"></span>
          <span class="minutes">25</span>
          <span class="seconds">00</span>
        </div>
      </div>
      <div id="breakClock" class="hidden">
        <h2>Break</h2>
        <div class="countdown">
          <span class="hours"></span>
          <span class="minutes">5</span>
          <span class="seconds">00</span>
        </div>
      </div>
    </div>
  </div>
</div>
<audio src="http://erincpotter.net/assets/ding.mp3" id="ding">Your browser does not support the <code>audio</code> element.</audio>
            
          
!
            
              *{
  box-sizing: border-box;
}

h1, h2, h3, h4, h5, h6, p {
  margin: 0;
}

body,
.directions,
.clock-wrapper,
.adjuster,
#clock,
.progress {
  display: -webkit-box; 
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}

body,
.col{
  -webkit-box-flex-direction: column;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
}

.row {
  -webkit-box-flex-direction: row;
  -webkit-flex-direction: row;
  -ms-flex-direction: row;
  flex-direction: row;
}

.col-to-row {
  -webkit-box-flex-direction: column;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
}

body,
.align-center {
  -webkit-box-align-items: center;
  -webkit-align-items: center;
  -ms-align-items: center;
  align-items: center;
}

.justify-center {
  -webkit-box-justify-content: center;
  -webkit-justify-content: center;
  -ms-justify-content: center;
  justify-content: center;
}

.show-block {
  display: block;
}

.show-inline-block {
  display: inline-block;
}

.hidden {
  display: none;
}

body {
  background: #444;
  color: #fff;
  font: 1.5em 'Open Sans', sans-serif;
  text-align: center;
}

h1 {
  font: bold 2.25em 'Pacifico', cursive;
  text-shadow: 2px 2px 5px #000;
}

.directions span {
  font-size: 20px;
  transition: 0.5s;
}

.clock-wrapper {
  margin-top: 25px;
  width: 100%;
  transition: 0.5s;
}

.adjuster {
  border: 2px solid #fff;
  border-radius: 5px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.adjuster h3 {
  background: #fff;
  color: #444;
  padding: 5px;
  font-size: 24px;
}

.length-adjuster {
  padding: 5px 15px;
}

.length-adjuster span {
  display: inline-block;
  line-height: 30px;
}

.count {
  width: 60px;
  font-size: 30px;
  font-weight: bold;
}

.btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 20px;
  transition: 0.3s;
}

.btn:hover {
  background: #fff;
  color: #444;
}

#break {
  margin-top: 15px;
}

#clock {
  margin-top: 15px;
  width: 300px;
  height: 300px;
  padding: 5px;
  border: 5px turquoise solid;
  border-radius: 50%;
  transition: 0.5s;
}

#clock:hover {
  cursor: pointer;
}

.progress {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

h2 {
  font-size: 50px;
}

.countdown {
  font-size: 50px;
}

.hours {
  display: none;
}

.hours::after,
.minutes::after {
  content: ':';
}





@media (min-width: 769px){
  .col-to-row {
    -webkit-box-flex-direction: row;
    -webkit-flex-direction: row;
    -ms-flex-direction: row;
    flex-direction: row;
  }
  
  .directions span {
    margin: 0 10px;
  }
  
  .clock-wrapper {
    margin-top: 40px;
  }
  
  #session {
    order: 0;
  }
  
  #break {
    margin-top: 0;
    order: 2;
  }
  
  #clock {
    margin: 0 3%;
    order: 1;
  }
}

@media (min-width: 1025px){ 
  .directions span {
    margin: 0 20px;
  }
  
  #clock {
    margin: 0 5%;
  }
}
            
          
!
            
              const sessionClock = $('#sessionClock');
const breakClock = $('#breakClock');
var sessionLength = {hours: 0, minutes: 25, seconds: 0, total: 1500};
var breakLength = {hours: 0, minutes: 5, seconds: 0, total: 300};
var time = {};
var playing = false;
var percent = 0;
var clock, countDown, inc;



function getClock(){
  time.hours = $(clock).find('.hours').text();
  if(time.hours === ''){
    time.hours = 0;
  } else {
    time.hours = parseInt(time.hours);
  }
  time.minutes = parseInt($(clock).find('.minutes').text());
  time.seconds = parseInt($(clock).find('.seconds').text());
}



//update numbers on #clock
function setClock(length){
  if(length.hours === 0){
    $(clock).find('.hours').hide().text(length.hours);
  } else {
    $(clock).find('.hours').text(length.hours).css('display', 'inline-block');
  }

  if(length.minutes < 10){
    $(clock).find('.minutes').text("0" + length.minutes);
  } else {
    $(clock).find('.minutes').text(length.minutes);
  }

  if(length.seconds < 10){
    $(clock).find('.seconds').text("0" + length.seconds);
  } else if(length.seconds === 60) {
    $(clock).find('.seconds').text("00");
  } else {
    $(clock).find('.seconds').text(length.seconds);
  }
}



function clockProgress(){
  var total, color;
  var currentCount = (time.hours * 60 + time.minutes) * 60 + time.seconds;

  if(clock === sessionClock){
    total = sessionLength.total;
    color = "turquoise";
  } else {
    total = breakLength.total;
    color = "yellowgreen";
  }

  inc = 1 / total * 100;

  var style = "linear-gradient(to bottom, " + color + ", " +  color + " " + percent + "%, #444 " + percent + "%)";

  $('.progress').css('background-image', style);

  percent += inc;

}



//run the countdown
function countdown(){
  if(time.seconds > 1){
    time.seconds--;
  } else {
    if(time.minutes > 0 || time.hours > 0){
      time.seconds = 60;
    } else {
      time.seconds--;
    }
  }

  if(time.seconds === 59 && time.minutes > 0){
    time.minutes--;
  } else if(time.seconds === 59 && time.minutes === 0){
    if(time.hours > 0){
      time.minutes = 59;
      time.hours--;
    }
  }

  if(time.hours === 0 && time.minutes === 0 && time.seconds === 0){
    $('#ding').get(0).play();
  }

  if(time.hours === 0 && time.minutes === 0 && time.seconds === -1){
    $(clock).toggleClass('show-block hidden').siblings().toggleClass('hidden show-block');

    if($(clock).siblings().attr('id') === 'sessionClock'){
      setClock(breakLength);
      clock = sessionClock;
      $('#clock').css("border", "5px turquoise solid");
    } else {
      setClock(sessionLength);
      clock = breakClock;
      $('#clock').css("border", "5px yellowgreen solid");
    }

    getClock();
    countdown();
    percent = 0;
  }

  clockProgress();
  setClock(time);
}



//adjust counters and clocks on btn click
$('.btn').click(function(){
  if(playing === false) {
    var counter = $(this).siblings('.count');
    var count = parseInt($(counter).text());
    var length = {hours: '', minutes: '', seconds: '', total: ''};
    
    if($(this).hasClass('plus')){
      count++;
    } else if($(this).hasClass('minus')){
      if(count>1){
        count--;
      }
    }
    
    //set counter text
    $(counter).text(count);

    //convert time to numbers
    if (count >= 60){
      length.hours = Math.floor(count / 60); 
      length.minutes = count % 60; 
    } else {
      length.hours = 0;
      length.minutes = count;
    }
    
    length.seconds = 0;
    length.total = count*60;

    //set clock and sessionLength/breakLength
    if($(counter).hasClass('sessionCount')){
      clock = sessionClock;
      sessionLength = length;
      setClock(sessionLength);
    } else if($(counter).hasClass('breakCount')) {
      clock = breakClock;
      breakLength = length;
      setClock(breakLength);
    }
  }
});



//start and pause countdown on clock click
$('#clock').click(function(){
  if($(this).find('.show-block').attr('id') === 'sessionClock'){
    clock = sessionClock;
  } else {
    clock = breakClock;
  }

  getClock();

  if(playing === false){
    countdown();
    countDown = setInterval(countdown, 1000);
    playing = true;
  } else {
    clearInterval(countDown);
    playing = false;
  }
});
            
          
!
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