cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              

<body>
<div class="container">
	<div id = "overview" class = "overview">
		<div id = "todo" class = "intervals">8</div>
		<div class = "intervals">
			<button id = "rep-plus">&plus;</button>
			<span id = intervals>8 REPS</span>
			<button id = "rep-minus">&minus;</button>
		</div>
		<div id = "done" class = "intervals">0</div>
	</div>
			
	<div class = "runner" id = "runner"><img  id = "runner1" src = "http://waywardpoints.com/timer/runner-30x35.png"></div>
	
	<div class = "clock">

			<div id = "go" class = "nav-section-left">
				<div class = "label">GO</div>
				<button id = "go-plus">&plus;</button>
				<button id = "go-minus">&minus;</button>
				<div class = "sm-label"><span id = "go-duration">00:30</span></div>
			</div>
			<div id = "rest" class = "nav-section-right">
				<div class = "label">REST</div>
				<button id = "rest-plus">&plus;</button>
				<button id = "rest-minus">&minus;</button>
				<div class = "sm-label"><span id = "rest-duration">01:30</span></div>
			</div>
		
			<div id = "time-display" class = "time-display">
				<div id = "time-left" class = "time-left">
					<span id = "time-remaining">00:30</span>
				</div>
				<div id = "reset" class = "reset">
					<button>START</button>
				</div>
			</div>
	</div>
</div>


                                                                                                                                                                                                                                                                                      

</body>

            
          
!
            
              body{
	background-color:#161818;
	/*padding: 0px 25px 0px 3px; kluge to keep inside right edge of screen */
	margin: 0px;
	-webkit-appearance: none;
}

div{
	
}
.clock {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-content: center;
	background-color:#161818;
	font-size: 46px;
	line-height: 1.2em;
	text-align: center;
	color: white;
	max-width: 100%;
}
.container{
	display: flex;
	flex-direction: column;
	flex-wrap: nowrap;
	justify-content: space-around;
	align-content: center;
	max-width: 800px;
	margin: auto;
}

.overview{
	
	padding: 3px 3px 10px 3px;
	display: flex;
	flex-wrap: nowrap;
	justify-content: space-between;
	align-content: center;
	background-color:#161818;
	font-size: 30px;
	line-height: 1.2em;
	text-align: center;
	color: white;
	max-width: 100%;
	
}
.intervals{
	margin: auto;
}
.runner{
	
	max-width: 800px;
	font-size: 30px;
	line-height: 1.2em;
	text-align: center;
	color: white;
	
}
#runner1{
	border: none;
	float: left;
	
}
#go{
	/*border: 2px solid gold;*/
}
.navigation{

	
}
.nav-section-left, .nav-section-right{
	border-radius: 26%;
	padding: 7px 0px 7px 0px;
	border: 5px solid black;
	

}
.nav-section-left{
	background-color: green;
	margin-left: 0px;
}

.nav-section-right{
	background-color: #CF000F;
	margin-right: 0px;
}
.label{
	text-align: center;
}
button{
	min-width: 48px;
	min-height: 48px;
	font-size: 30px;
	font-weight: bold;
	border-radius: 26%;
	margin: 7px;
	-webkit-appearance: none;
	/*pointer-events: none;*/
	background-color: white;
	
}
.time-display{
	font-size: 77px;
	line-height: 1.2em;
	margin: auto;
}
.sm-label{
	font-size: 35px;
	line-height: 1.2em;
}
.reset{
	max-height: 1.2em;
	display:flex;
	justify-content:center;
	align-items:center;
	-webkit-appearance: none;
}

 @media screen and (max-width: 475px) {
	.nav-section-left{
		order: 1;
		width: 45%
	}
	.nav-section-right{
		order: 2;
		width: 45%;
	}
	.time-display{
		order: 3;
	}
}
 @media screen and (min-width: 476px){
	.nav-section-left{
	order: 1;
	}
	.nav-section-right{
	order: 3;
	}
	.time-display{
	order: 2;
	}

}
            
          
!
            
              /* Thank you to:
 * https://www.sitepoint.com/build-javascript-countdown-timer-no-dependencies/
 * https://www.sitepoint.com/creating-accurate-timers-in-javascript/
 * <a href="http://cliparts.co">ClipArts</a>
 */

var numIntervals = 8,
goDuration = 30,  
restDuration = 90,
goTimeRemaining = 30,
restTimeRemaining = 90,
elapsed,
timer,
//totalReps = 8,
reps =0;
going = false;

document.addEventListener("DOMContentLoaded", function(event) {// don't do anything until page loads
	console.log("DOM fully loaded and parsed");
	
	assignEventHandlers();
	
	function assignEventHandlers(){
		

		document.getElementById("reset").addEventListener("click", function(event){
			event.preventDefault(); // prevents iphone from resizing on doubleclick
			reset();
			console.log('reset clicked');
		});
		document.getElementById("go-plus").addEventListener("click", function(event){ //TODO prevent negative or 0 values, fix screen shut down
			event.preventDefault();
			if (restDuration < 5930){//test that time does not go over 99:99
				goDuration = goDuration + 5;
				document.getElementById('go-duration').innerHTML = formatTime(goDuration);
				if (!going){
					console.log('not going');
					document.getElementById('time-remaining').innerHTML = formatTime(goDuration);
				}
				console.log('go-plus clicked');
			}
		});
		document.getElementById("go-minus").addEventListener("click", function(event){
			event.preventDefault();
			if (goDuration > 5){ // work time must be 5 sec or more
				goDuration = goDuration - 5;
				document.getElementById('go-duration').innerHTML = formatTime(goDuration);
				if (!going){
					console.log('not going');
					document.getElementById('time-remaining').innerHTML = formatTime(goDuration);
				}
				console.log('go-minus clicked');
			}
		});
		document.getElementById("rest-plus").addEventListener("click", function(event){
			event.preventDefault();
			if (restDuration < 5930){//test that time does not go over 99:99
				restDuration = restDuration + 5;
				document.getElementById('rest-duration').innerHTML = formatTime(restDuration);
				console.log('rest-plus clicked');
			}
		});
		document.getElementById("rest-minus").addEventListener("click", function(event){
			event.preventDefault();
			if (restDuration > 5){ // rest time must be 5 sec or more
				restDuration = restDuration - 5;
				document.getElementById('rest-duration').innerHTML = formatTime(restDuration);
				console.log('rest-minus clicked');
			}
		});
		document.getElementById("rep-plus").addEventListener("click", function(event){
			event.preventDefault();
			if (numIntervals < 99){ // no more than 99 or layout has to be updated - no sane person does 99 intervals anyway
				numIntervals = numIntervals + 1;
				document.getElementById('intervals').textContent = numIntervals + " REPS";
				document.getElementById('todo').textContent = numIntervals - reps;
				document.getElementById('done').textContent = reps;
				console.log('rest-minus clicked');
			}
		});
		document.getElementById("rep-minus").addEventListener("click", function(event){
			event.preventDefault();
			if (numIntervals > 1){ // must have at least one interval
				numIntervals = numIntervals - 1;
				document.getElementById('intervals').textContent = numIntervals + " REPS";
				document.getElementById('todo').textContent = numIntervals - reps;
				document.getElementById('done').textContent = reps;
				console.log('rep-minus clicked');
			}
		});
	}
	
	function formatTime(seconds){ 
		var mmss;
		mmss = ('0' + (Math.floor((seconds)/60))).slice(-2) + ':' + ('0' + ((seconds) % 60)).slice(-2);
		return mmss;		
	}
	
	function reset(){ // starts or restarts timer 
		
		clearInterval(timer);
		document.getElementById('go').style.border = '5px solid gold';
		reps = 0;
		going = true;
		document.getElementById('rest').style.border = '5px solid black';
		document.getElementById('runner').innerHTML = '<img  id = "runner1" src = "http://waywardpoints.com/timer/runner-30x35.png"></img>';
		document.getElementById('todo').textContent = numIntervals;
		document.getElementById('done').textContent = 0;
		changeTimer(new Date().getTime(), 0);  // get system time to use as start time for each period
	}
	
	function changeTimer(start, elapsed){// start is sysclock time when user starts, duration is global b/c user changes it anytime
		//var start = new Date().getTime(),
		
		var duration;
		
		console.log("change timer called, going = " + going + "restDuration = " + restDuration);
		moveRunner(707, 0);
		timer = window.setInterval(function()
			{if (going){ // test to see if user currently resting or in an interval
				duration = goDuration;
				console.log("goDuration = " + goDuration);
			} else{
				duration = restDuration;
				console.log("restDuration = " + restDuration);
			}//end else
				
			if (duration - elapsed > 0){
			    var timeRemaining = new Date().getTime() - start;
				elapsed = Math.floor(timeRemaining / 1000);// number of seconds elapsed
			//	format timeRemaining as string MM:SS
				timeRemaining =  formatTime(duration-elapsed);
				document.getElementById('time-remaining').innerHTML = timeRemaining;
				
				if (going){
					moveRunner(44, 0, elapsed);
				}
			} //end if
			else{
				going = !going;//toggle timer to measure rest time/work time
				if (going){
					document.getElementById('time-remaining').innerHTML = formatTime(goDuration);
					document.getElementById('go').style.border = '5px solid gold';
					document.getElementById('rest').style.border = '5px solid black';
					//moveRunner(0,0,0); -- that was off by 30 px
					document.getElementById('runner1').style.transform =  'translate(0px, 0px)';
				}else {
					document.getElementById('time-remaining').innerHTML = formatTime(restDuration);
					document.getElementById('go').style.border = '5px solid black';
					document.getElementById('rest').style.border = '5px solid gold';
					document.getElementById('todo').innerHTML = numIntervals - reps -1;
					document.getElementById('done').innerHTML = reps + 1;
					reps +=1;
					moveRunner(0,5,goDuration);
					console.log("runner rests: ");
				}
			
				clearInterval(timer);
				console.log("here reps = "+ reps + "numIntervals = " + numIntervals);
				if (reps < numIntervals){
					changeTimer(new Date().getTime(), 0);
					console.log(reps + " is reps");
				}else{//-- stop the program when all reps completed
					reps = 0;
					var stuff;
					stuff = '<img  id = "runner1" src = "http://waywardpoints.com/timer/runner-30x35.png"></img>' +  'Workout Complete!'
					document.getElementById('runner').innerHTML = stuff;
					document.getElementById('time-remaining').innerHTML = '00:00';
				}
			} //end else
		}, 1000); // end setInterval
	}	//end ChangeTimer
});// end DOMContentLoaded

function moveRunner(x, y, timeDone){
	var position, totalWidth, fractionComplete;
	totalWidth = document.getElementById('runner').offsetWidth;
	fractionComplete = (timeDone/goDuration*totalWidth) - 30; //image is 30 px wide
	position = 'translate(' + fractionComplete +'px, ' + y + 'px)';
	console.log(totalWidth);
	if (going){
	document.getElementById('runner1').style.transform = position;
		}else{
			position = 'translate(' + (totalWidth - 30) +'px, 0px) rotate(255deg)';
			document.getElementById('runner1').style.transform =  position;
			console.log(position);
		}
	/* TODO maybe?  need to add prefixes to transform
	 * such as...
	* 	-ms-transform: translate(50px, 0px);  //IE 9 
    -webkit-transform: translate(50px, 0px); //Safari 
    transform: translate(50px, 0px);
	 * 
	 * 
	 */
}

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

Console