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

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 class="outer-wrapper">
<h1>Pomodoro Timer</h1>
<div class="settings">
  <div id="break">
    <h4>Break Time</h4>
    <span class="decrement">-</span> 
    <span class="time">5</span> 
    <span class="increment">+</span>
  </div>

  <div id="session">
    <h4>Work Time</h4>
    <span class="decrement">-</span> 
    <span class="time">25</span> 
    <span class="increment">+</span>
  </div>
</div>


    <div id="timer">
      <div id="current-session"></div>
      <div id="count-down">25 : 00</div>
      <span id="session-count">Round 1 / 4</span>
      <div id="progress"></div>
    </div>
  
    <div class="controls">
      <button id="start">Start</button>
      <button id="pause" class="running">Pause</button>
      <button id="reset" class="running">Reset</button>
    </div>
</div>
              
            
!

CSS

              
                body {
  font-family: 'Roboto', sans-serif;
  font-weight: light;
  background-color: #212121;
  color: #e0e0e0;
  /* Trying some non-standards stuff */
  -webkit-touch-callout: none; 
  -webkit-user-select: none;   
  -moz-user-select: none;      
  -ms-user-select: none; 
  user-select: none;           
}

.outer-wrapper {
  width: 100%;
  max-width: 768px;
  margin: 0 auto;
  box-sizing: border-box;
}

h1 {
  color: #e0e0e0;
  margin-bottom: 0;
  font-weight: 300;
}

h4 {
  margin: 0;
  font-weight: 300;
}

.settings {
  width: 100%;
  box-sizing: border-box;
  font-size: 0px;
  margin-top: 10px;
  padding: 15px 0;
  border-top: 1px solid #616161;
  border-bottom: 1px solid #616161;
}

#break,
#session {
  width: 50%;
  display: inline-block;
  box-sizing: border-box;
  font-size: 20px;
  text-align: center;
}

#break {
  border-right: 1px solid #616161;
}

.increment,
.decrement {
  cursor: pointer;
}

.increment {
  font-size: 30px;
  line-height: 48px;
  vertical-align: top;
}

.time,
.decrement {
  font-size: 40px;
}

#timer {
  text-align: center;
  font-size: 70px;
  margin: 0 auto 10px;
  position: relative;
  width: 100%;
  min-height: 300px;
}

#current-session {
  font-size: 50px;
  position: absolute;
  top: 28%;
  left: 0;
  right: 0;
  margin: auto;
}

#count-down {
  position: absolute;
  top: 55%;
  left: 0;
  right: 0;
  margin: auto;
}

#session-count {
  position: absolute;
  top: 85%;
  left: 0;
  right: 0;
  margin: auto;
  font-size: 30px;
}

#progress {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 0;
    width: 80%;
    margin: auto;
    max-width: 360px;
}

.controls {
  text-align: center;
  position: fixed;
  right: 0;
  bottom: 5%;  
  left: 0;
}

button {
  border-image: none;
  background-color: inherit;
  border: 1px solid #e0e0e0;
  color: #e0e0e0;
  font-size: 30px;
  padding: 10px 20px;
  cursor: pointer;
}

button:focus {
  outline: none;
}

@media screen and (max-width: 400px) {
  #current-session {
    font-size: 40px;
    top: 23%;
  }
  #count-down {
    font-size: 60px;
    top: 43%;
  }
  #session-count {
    font-size: 25px;
    top: 70%;
  }
  .controls {
    bottom: 3%;
  }
}
              
            
!

JS

              
                function pomodoro() {
	var breakTime = $('#break .time').text();
	var interval = $('#session .time').text();
	var h = 0;
	var m = 0;
	var s = 0;
	var flag = '';
	var setInt, opts, hasStarted;
	var sessionCount = 1;
	var percentCurrent = 0;
	var percentBase = 0;
	var percentComplete = 0;

	// Progress Indicator Setup
	var pCircle = new ProgressBar.Circle('#progress', {
	  color: 'rgb(252,63,69)',
	  // This has to be the same size as the maximum width to
	  // prevent clipping
	  strokeWidth: 1,
	  trailColor: 'rgb(33,33,33)',
	  trailWidth: 1,
	  easing: 'linear',
	  duration: 1000,
	  text: {
	    autoStyleContainer: false
	  },
	  step: function(state, circle) {
	  	if (flag === 'work') {
	  		circle.path.setAttribute('stroke', 'rgb(252,63,69)');
	  	} else {
	  		circle.path.setAttribute('stroke', 'rgb(0,200,63)');	
	  	}
	  }
	});

	// Decrement time units appropriatly, firing other functions when needed
	function countDown() {
		h = parseInt(h);
		m = parseInt(m);
		s = parseInt(s);
		if ( s >= 0 ) {
			if ( s-1 === -1 && m > 0 ) {
				if ( m-1 === -1 && h > 0 ) {
					h--;
					m = 59;
					updateTimer();
				} else {		
				m--;
				s = 59;
				updateTimer();
				}
			} else if ( s-1 === -1 && m === 0 && h === 0 ) {
				advanceCycle();
			} else {
			s--;
			updateTimer();
			}
		}		
	};

	// Update the page with new time, and percentage completed
	function updateTimer() {

		// Update progress circle
		percentCurrent = (s + (m*60) + (h*60*60));
		if( flag === 'work') { 
			percentBase = (interval * 60);
		} else { 
			percentBase = (breakTime * 60);
		};
		percentComplete = 1 - ( percentCurrent / percentBase );
		pCircle.animate(percentComplete);  // Number from 0.0 to 1.0

		//Update Clock
		h = timeCheck(h);
		m = timeCheck(m);
		s = timeCheck(s);
		if ( interval > 60 ) {
			$('#count-down').text(h + ' : ' + m + ' : ' + s);
		} else {
			$('#count-down').text(m + ' : ' + s);
		}

	};

	// Values less than 10 are kept at 2 digits
	function timeCheck(i) {
		if (i < 10 && i.toString().length < 2) {
			i = '0' + i;
		}
		return i;
	}

	// At the end of a countDown, transition to next count down cycle
	function advanceCycle() {

		// Check if a pomodoro (4 rounds) have been completed
		if ( sessionCount === 4 && flag === 'work' ) {
			endPomo();
		} else {

			// Set flag for the new cycle
			if (flag === 'work' && sessionCount < 5) {
				flag = 'break';
				$('#current-session').text('Break!');
				pCircle.set(0);
			} else if (flag === 'break' && sessionCount < 5) {
				flag = 'work';
				$('#current-session').text('Work');
				pCircle.set(0);
				advanceCycleUI();
			}

			// Set variables for next cycle
			if (flag === 'work' && sessionCount < 5) {
				if ( interval > 60 ) {
					h = Math.floor(interval / 60);
					m = interval % 60;
					$('#count-down').text(h + ' : ' + m + ' : ' + s);
          updateTimer();
				} else {
					m = interval - 1;
					if ( m < 10 ) {
						m = '0' + m;
					}
					s = 59;
					$('#count-down').text(m + ' : ' + s);
          updateTimer();
				}	
			} else if (flag === 'break' && sessionCount < 5) {
				if ( breakTime > 60 ) {
					h = Math.floor(breakTime / 60);
					m = breakTime % 60;
					$('#count-down').text(h + ' : ' + m + ' : ' + s);
          updateTimer();
				} else {
					m = breakTime - 1;
					if ( m < 10 ) {
						m = '0' + m;
					}
					s = 59;
					$('#count-down').text(m + ' : ' + s);
          updateTimer();
				}	
			}
		}
	}

	// Advance the UI with each cycle advance
	function advanceCycleUI () {
		if ( sessionCount < 4 ) {
			sessionCount++;
			$('#session-count').text('Round ' + sessionCount + ' / 4');
		} else if ( sessionCount === 4) {
			$('#session-count').text('Round 4 / 4');
			sessionCount++;
		}
	}

	//
	function endPomo () {
		clearInterval(setInt);
		$('#current-session').text('Done!');
	}

	// Hide pause and reset buttons on page load for later toggling
	$('.running').toggle();

	// Update timer settings down
	$('.decrement').on('click', function(e) {
		switch($(this).parent()[0].attributes[0].nodeValue) {
			case 'break':
				if ( breakTime > 1 ) {
					breakTime--;
					$('#break .time').text(breakTime);
					$('#count-down').text(interval + ' : 00');
					if (hasStarted) {
						$('#start').toggle();
						$('.running').toggle();
						hasStarted = false;		
					}
					$('#current-session').text('');
					clearInterval(setInt);
					setInt = false;
					pCircle.set(0);
				}
				break;
			case 'session':
				if ( interval > 1 ) {
					interval--;
					$('#session .time').text(interval);
					$('#count-down').text(interval + ' : 00');
					if (hasStarted) {
						$('#start').toggle();
						$('.running').toggle();
						hasStarted = false;	
					}
					$('#current-session').text('');
					clearInterval(setInt);
					setInt = false;
					pCircle.set(0);
				}
				break;
			default:
				break;
		}
	});

	// Update timer settings up
	$('.increment').on('click', function(e) {
		
		switch($(this).parent()[0].attributes[0].nodeValue) {
			case 'break':
				breakTime++;
				$('#break .time').text(breakTime);
				$('#count-down').text(interval + ' : 00');
				if (hasStarted) {
						$('#start').toggle();
						$('.running').toggle();
						hasStarted = false;						
					}
				$('#current-session').text('');
				clearInterval(setInt);
				setInt = false;
				pCircle.set(0);
				break;
			case 'session':
				interval++;
				$('#session .time').text(interval);
				$('#count-down').text(interval + ' : 00');
				if (hasStarted) {
						$('#start').toggle();
						$('.running').toggle();
						hasStarted = false;						
					}
				$('#current-session').text('');
				clearInterval(setInt);
				setInt = false;
				pCircle.set(0);
				break;
			default:
				break;
		}
	});

	// Start a brand new pomodoro
	$('#start').on('click', function(e) {
		hasStarted = true;
		if ( interval > 60 ) {
			h = Math.floor(interval / 60);
			m = interval % 60;
			$('#count-down').text(h + ' : ' + m + ' : ' + s);
		} else {
			m = interval - 1;
			if ( m < 10 ) {
				m = '0' + m;
			}
			s = 59;
			$('#count-down').text(m + ' : ' + s);
		}	
		$('#start').toggle();
		$('.running').toggle();
		flag = 'work';
		$('#current-session').text('Work');
    updateTimer();
		setInt = setInterval(countDown, 1000);
		$('#session-count').text('Round ' + sessionCount + ' / 4');

	});

	// Pause the timer
	$('#pause').on('click', function(e) {
		if ( $('#pause').text() === 'Pause') {
			$('#pause').text('Resume');
			clearInterval(setInt);
			setInt = false;
		} else {
			$('#pause').text('Pause');
			setInt = setInterval(countDown, 1000);
		}
	});

	// Reset timer to initial load state
	$('#reset').on('click', function(e) {
		clearInterval(setInt);
		setInt = false;
		hasStarted = false;
		sessionCount = 1;
		percentComplete = 0;
		pCircle.set(0);
		$('#count-down').text(interval + ' : 00');
		$('#current-session').text('');
		$('#session-count').text('Round 1 / 4');
		$('#start').toggle();
		$('.running').toggle();
		$('#pause').text('Pause');
	});

}

pomodoro();
              
            
!
999px

Console