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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!--Count Down-->
<div id="timeClock" onclick="javascript:toggleTime()" title="Time Left">
    <span id="time" class="timeClockInput">00:00</span>
</div>
<!--Count Up-->
<div id="countUpBox" title="Time Elapsed">
<span class="playTimeArea" id="countUp"><span id="countUpMin">00</span>:<span id="countUpSec">00</span></span></div>
<br/><br/>
<br/><br/>
<br/><br/>
<div id="timeArea">
  <input id="minutes" type="number" placeholder="Minutes left..." min="0">
  <br/>
  <button id="startClock" type="button" onclick="startCountdown()"><i class="fa fa-play"></i></button>
  <br/>
  <button id="pauseBtn" type="button" onclick="stopCountdown()"><i class="fa fa-redo-alt"></i></button>
	</div>
              
            
!

CSS

              
                body{
	overflow:hidden;
	background-color:#ccc;
}

#countUpBox, #timeClock{
	position:relative;
	font-size:3em;
	margin:0 auto;
	padding:10px;
	border:3px solid #000;
}
#timeClock{
	float:left;
}
#countUpBox{
	float:right;
}

#startClock{
	width:calc(70% - 7px);
	position:absolute;
	right:0%;
	bottom:0%;
	transform:translate(0%);
	font-size:2.5em;
	color:green;
	padding:10px;
	margin-bottom:10px;
	margin-right:10px;
	text-align:center;
	border-radius:0px 20px 20px 0px;
	border:3px solid green;
	background-color:rgb(0,255,0);
	cursor:pointer;
}
#startClock:hover{
	opacity:0.6;
}

#pauseBtn{
	width:calc(30% - 10px);
	position:absolute;
	left:0%;
	bottom:0%;
	transform:translate(0%);
	font-size:2.5em;
	color:darkred;
	padding:10px;
	margin-bottom:10px;
	margin-left:10px;
	text-align:center;
	border-radius:20px 0px 0px 20px;
	border:3px solid darkred;
	background-color:rgb(255,0,0);
	cursor:pointer;
}
#pauseBtn:hover{
	opacity:0.6;
}
#minutes{
	width:80%;
	position:absolute;
	left:50%;
	top:50%;
	transform:translate(-50%,-50%);
	font-size:1.5em;
	padding:10px;
	margin-right:10px;
	text-align:center;
	max-width:400px;
}

.pulse{
  animation: pulse 0.5s linear infinite;
}
@keyframes pulse{
  0%{font-size:100%;}
  50%{font-size:110%;}
  100%{font-size:100%;}
}
              
            
!

JS

              
                var secondsRemaining;
var down;
var up;
var minutesLabel = document.getElementById("countUpMin");
var secondsLabel = document.getElementById("countUpSec");

//for countUp function
var totalSeconds = 0;

var pauseBtn = document.getElementById("pauseBtn");
var startClock = document.getElementById("startClock");

//countDown timer
function countDown(){
	// grab the time area
	var timeDisplay = document.getElementById("time");

	// turn the seconds into mm:ss
	var min = Math.floor(secondsRemaining / 60);
	//floor seconds to keep it from showing weird decimal places
	var sec = Math.floor(secondsRemaining - (min * 60));

	//add a leading zero (as a string value) if seconds less than 10
	if (sec < 10) {
		sec = "0" + sec;
	}
	if (min < 10) {
		min = "0" + min;
	}

	// concatenate with colon
	var message = min.toString() + ":" + sec.toString();

	// now change the display
	timeDisplay.innerHTML = message;

	if(secondsRemaining < 10 && secondsRemaining > 0){
		$("#time").addClass("pulse"); 
	}
	
	// when timer reaches zero
	if (secondsRemaining === 0){
		clearInterval(down);
		$("#time").removeClass("pulse"); 
    //stopCountdown();
	}

	//subtract from seconds remaining
	secondsRemaining--;

}

function stopCountdown(){
  document.getElementById("timeClock").innerHTML = '<span id="time" class="timeClockInput">00:00</span>';
  document.getElementById("countUpMin").innerHTML = '00';
	document.getElementById("countUpSec").innerHTML = '00';
	//for countUp function
	totalSeconds = 0;
	// stop any ongoing countdowns
	clearInterval(up);
  clearInterval(down);
	//set the push of play back to a start event
	startClock.innerHTML = '<i class="fa fa-play"></i>';
	startClock.style.backgroundColor = "rgb(0,255,0)";
	startClock.style.color = "green";
	startClock.style.border = "3px solid green";
	$("#startClock").attr("onclick", "startCountdown()");
	
	$("#timeArea").removeClass('paused');
	$("#timeArea").addClass('paused');
}

function startCountdown(){
  
	//for countUp function
	totalSeconds = 0;
	// stop any ongoing countdowns
	clearInterval(up);
  clearInterval(down);
	
  $("#timeArea").removeClass('paused');
	
  //document.getElementById("pauseBtn").innerHTML='<i class="fa fa-pause"></i>';
	
	// get contents of the "minutes" text box
	var minutes = document.getElementById("minutes").value;
	
	// check if not a number
	if (isNaN(minutes)||minutes == ""||minutes==null){
		alert("Enter time in minutes!");
		return; // stops function if true
	}

	// how many seconds
	secondsRemaining = minutes * 60;
	
	
	//up
	up = setInterval(countUp, 1000);
	
	//every second, call the "countDown" function
	// have to make it into a variable so that you can stop the interval later!!!
	down = setInterval(countDown, 1000);
	
	//set the play button to the pause button
	startClock.innerHTML = '<i class="fa fa-pause"></i>';
	startClock.style.backgroundColor = "yellow";
	startClock.style.color = "rgb(200,200,0)";
	startClock.style.border = "3px solid rgb(200,200,0)";
	
	//set the play button click to the pause event
	$("#startClock").attr("onclick", "pauseCountdown()");
}

function pauseCountdown(){
  var pauseBtn = document.getElementById("pauseBtn");
  $("#timeArea").toggleClass('paused');
  if($("#timeArea").hasClass('paused')){
    //pause countdown
    clearInterval(down);
    startClock.innerHTML='<i class="fa fa-play"></i>';
	startClock.style.backgroundColor = "rgb(0,255,0)";
	startClock.style.color = "green";
	startClock.style.border = "3px solid green";
		
		//pause countUp
		clearInterval(up);
		
  } else {
		//restart countUp
		up = setInterval(countUp, 1000);
    //restart countdown
    down = setInterval(countDown, 1000);
    startClock.innerHTML='<i class="fa fa-pause"></i>';
		startClock.style.backgroundColor = "yellow";
		startClock.style.color = "rgb(200,200,0)";
		startClock.style.border = "3px solid rgb(200,200,0)";
		
  }
}

//countUp
function countUp() {
  secondsLabel.innerHTML = pad(totalSeconds % 60);
  minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
	++totalSeconds;
}
//countUp Helper
function pad(val) {
  var valString = val + "";
  if (valString.length < 2) {
    return "0" + valString;
  } else {
    return valString;
  }
}

//prevent things other than numbers or decimals from being inputted
// Select your input element.
var number = document.getElementById('minutes');

// Listen for input event on numInput.
number.onkeydown = function(e) {
    if(!((e.keyCode > 95 && e.keyCode < 106)
      || (e.keyCode > 47 && e.keyCode < 58) 
      || e.keyCode == 8
			|| e.keyCode == 190)) {
        return false;
    }
}
              
            
!
999px

Console