Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!--
responsive clock
	| set width using the data-width attribute
	| all css units are valid (px, %, vw, vh ...)
-->

<main>
	<div id="clock" data-width="250px">
		<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path id="minutesA" d="m50 1.5c-26.5 0-48 22-48 48.5 0 26.5 21.5 48 48 48.5 26.5 0 48-22 48.5-48.5-.5-26.5-21.5-48.5-48-48.5h-.5" fill="none" stroke="#456990"/></svg>
		<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path id="minutesB" d="m50 1.5c-26.5 0-48 22-48 48.5 0 26.5 21.5 48 48 48.5 26.5 0 48-22 48.5-48.5-.5-26.5-21.5-48.5-48-48.5h-.5" fill="none" stroke="#e06b64"/></svg>
		<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path id="secondsPath" d="m50 1.5c-26.5 0-48 22-48 48.5 0 26.5 21.5 48 48 48.5 26.5 0 48-22 48.5-48.5-.5-26.5-21.5-48.5-48-48.5h-.5" fill="none" stroke="#2f3233"/></svg>
		<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path id="seconds" d="m50 1.5c-26.5 0-48 22-48 48.5 0 26.5 21.5 48 48 48.5 26.5 0 48-22 48.5-48.5-.5-26.5-21.5-48.5-48-48.5h-.5" fill="none" stroke="#fff"/></svg>
		
		<div id="hour">
			<div></div>
			<div></div>
			<div></div>
			<div></div>
			<div></div>
			<div><span></span></div>
		</div>
		
	</div>
</main>
              
            
!

CSS

              
                main {
	width: 100%;
	height: 100%;
	display: -webkit-box;
	display: -webkit-flex;
	display: -ms-flexbox;
	display: flex;
	-webkit-justify-content: space-around;
	    -ms-flex-pack: distribute;
	        justify-content: space-around;
	-webkit-box-align: center;
	-webkit-align-items: center;
	    -ms-flex-align: center;
	        align-items: center;
	background-image: radial-gradient(at top left,#585F63, #3c4042);
}

#clock {
	display: -webkit-box;
	display: -webkit-flex;
	display: -ms-flexbox;
	display: flex;
	-webkit-box-pack: center;
	-webkit-justify-content: center;
	    -ms-flex-pack: center;
	        justify-content: center;
	-webkit-box-align: center;
	-webkit-align-items: center;
	    -ms-flex-align: center;
	        align-items: center;
	border-radius: 50%;
}

svg:first-of-type,
svg:nth-of-type(2) {
	width: 100%;
	height: 100%;
	position: absolute;
	top: 0;
	left: 0;
	stroke-width: 40;
	border-radius: 50%;
}

svg:last-of-type,
svg:nth-of-type(3) {
	width: 104%;
	height: 104%;
	position: absolute;
	top: -2%;
	left: -2%;
	stroke-width: 1.5;
	border-radius: 50%;
}

svg:last-of-type {
	stroke-width: 2;
}

#hour {
	width: 80%;
	height: 80%;
	position: absolute;
	top: 10%;
	left: 10%;
	background: #transparent;
	border-radius: 50%;
}

#hour div {
	width: 100%;
	height: 100%;
	position: absolute;
	top: 0;
	left: 0;
}

#hour div:nth-child(2),
#hour div:nth-child(4) {
	-webkit-transform: rotate(30deg);
	        transform: rotate(30deg);
}

#hour div:nth-child(3),
#hour div:nth-child(5) {
	-webkit-transform: rotate(-30deg);
	        transform: rotate(-30deg);
}

#hour div::before,
#hour div::after {
	content: '';
	position: absolute;
	background: #282828;
}

#hour div:first-child::before {
	width: 2%;
	height: 12%;
	top: 10%;
	left: 49%;
}

#hour div:nth-child(2)::before,
#hour div:nth-child(3)::before {
	width: 2%;
	height: 4%;
	top: 10%;
	left: 49%;
}

#hour div:first-child::after {
	width: 2%;
	height: 12%;
	bottom: 10%;
	left: 49%;
}

#hour div:nth-child(2)::after,
#hour div:nth-child(3)::after {
	width: 2%;
	height: 4%;
	bottom: 10%;
	left: 49%;
}

#hour div:last-child::before {
	width: 12%;
	height: 2%;
	top: 49%;
	left: 10%;
}

#hour div:nth-child(4)::before,
#hour div:nth-child(5)::before {
	width: 4%;
	height: 2%;
	top: 49%;
	left: 10%;
}

#hour div:last-child::after {
	width: 12%;
	height: 2%;
	top: 49%;
	right: 10%;
}

#hour div:nth-child(4)::after,
#hour div:nth-child(5)::after {
	width: 4%;
	height: 2%;
	top: 49%;
	right: 10%;
}

#hour span {
	-webkit-transition: all 1s linear;
	transition: all 1s linear;
	width: 3%;
	height: 40%;
	position: absolute;
	bottom: 45%;
	left: 48.5%;
	background: #fff;
	border-top-left-radius: 100%;
	border-top-right-radius: 100%;
	-webkit-transform-origin: 50% 88%;
	        transform-origin: 50% 88%;
}
              
            
!

JS

              
                // measure the length of the SVG path. All four will be the same
var pathLength = document.getElementById('minutesA').getTotalLength();

// calculate portion of pathLength that corresponds to
// one second and create global var
var addSecond = pathLength/60;
var second = 0;

// calculate portion of pathLength that corresponds to
// one second in one minute and create global var
var addMinuteSecond = addSecond/60;
var minute = 0;

// calculate degrees out of 360 that represent one second
// in a 12 hour period and create global var
var addHourSecond = ((360/12)/60)/60;
var hour = 0;

// ∞∞ build clock fn
function buildClock() {
	var clock = $('#clock');
	
	// retreive desired width
	var width = clock.data('width');

	// set width and inject 10x10 px png to ensure it's a square
	clock.css({'width': width, 'height': width})
}

// ∞∞ set clock fn
function setClock() {
	// get JS Date
	var time = new Date();
	
	// get seconds and convert to clock units
	var getSecond = time.getSeconds();
	var setSecond = getSecond*addSecond;

	// get minutes and convert to clock units
	var getMinute = time.getMinutes();
	var setMinute = getMinute*addMinuteSecond*60;

	// get hours
	var getHour = time.getHours();
	
	// convert 13h to 23h to 12h time
	var splitDay = (getHour > 11) ? getHour-12 : getHour;
	
	// convert hours to number of degrees (30deg per hour)
	// and add minutes to hour hand for continuous animation
	var setHour = (splitDay*30)+(getMinute*(addHourSecond*60));
	
	// prepare SVG paths
	$('#minutesB').css({'stroke-dasharray': pathLength});
	$('#seconds').css({'stroke-dasharray': pathLength/60 + ' ' + (pathLength/60)*59});
	
	// add necessary running transition
	setTimeout(function() {
		$('#minutesB, #seconds').css({'transition': 'all 1s linear'});
		
		// set clock
		setTimeout(function() {
			$('#seconds').css({'stroke-dashoffset': setSecond});
			$('#minutesB').css({'stroke-dashoffset': setMinute});
			$('#hour span').css({'transform': 'rotate(' + setHour + 'deg)'});
		}, 50);
	}, 50);
	
	// refresh global vars
	second = setSecond+addSecond;
	minute = setMinute+addMinuteSecond;
	hour = setHour+addHourSecond;
}

// ∞∞ run clock fn
function runClock() {
	
	// add global var values to correct elements
	$('#seconds').css({'stroke-dashoffset': second});
	$('#minutesB').css({'stroke-dashoffset': minute});
	$('#hour span').css({'transform': 'rotate(' + hour + 'deg)'});

	// refresh global vars
	second += addSecond;
	minute += addMinuteSecond;
	hour += addHourSecond;
}

// build
buildClock();

// use timeout to make sure elements have been built
setTimeout(setClock, 100);

// set one second intervals for running the clock
setInterval(runClock, 1000);
              
            
!
999px

Console