css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <div class="clock">

	<div class="digit tenhour">
		<span class="base"></span>
		<div class="flap over front"></div>
		<div class="flap over back"></div>
		<div class="flap under"></div>
	</div>

	<div class="digit hour">
		<span class="base"></span>
		<div class="flap over front"></div>
		<div class="flap over back"></div>
		<div class="flap under"></div>
	</div>
	
	<div class="digit tenmin">
		<span class="base"></span>
		<div class="flap over front"></div>
		<div class="flap over back"></div>
		<div class="flap under"></div>
	</div>

	<div class="digit min">
		<span class="base"></span>
		<div class="flap over front"></div>
		<div class="flap over back"></div>
		<div class="flap under"></div>
	</div>
	
	<div class="digit tensec">
		<span class="base"></span>
		<div class="flap over front"></div>
		<div class="flap over back"></div>
		<div class="flap under"></div>
	</div>

	<div class="digit sec">
		<span class="base"></span>
		<div class="flap over front"></div>
		<div class="flap over back"></div>
		<div class="flap under"></div>
	</div>
	
</div>

            
          
!
            
              $flipColour: #fff;
$flipColourDark: darken($flipColour, 35%);
$textColour: #333;
$textColourDark: darken($textColour, 35%);

html {
	height: 100%;
}

body {
	height: 100%;
	background: #85D8CE;
	background: linear-gradient(135deg, #085078, #85D8CE);
}

.digit {
	position: relative;
  float: left;
  width: 10vw;
  height: 15vw;
  background-color: $flipColour;
  border-radius: 1vw;
	text-align: center;
  font-family: Oswald, sans-serif;
  font-size: 11vw;
}

.base {
	display: block;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: $textColour;
}
  
.flap {
	display: none;
	position: absolute;
	width: 100%;
	height: 50%;
	background-color: $flipColour;
	left: 0;
	top: 0;
	border-radius: 1vw 1vw 0 0;
	transform-origin: 50% 100%;
	backface-visibility: hidden;
	overflow: hidden;
	
	&::before {
		content: attr(data-content);
		position: absolute;
		left: 50%;
	}
	
	&.front::before,
	&.under::before {
		top: 100%;
		transform: translate(-50%, -50%);
	}
	
	&.back {
		transform: rotateY(180deg);
		&::before {
			top: 100%;
			transform:  translate(-50%, -50%) rotateZ(180deg);
		}
	}

	&.over {
		z-index: 2;
	}
	
	&.under {
		z-index: 1;
	}
	
	&.front {
		animation: flip-down-front 300ms ease-in both;
	}
	
	&.back {
		animation: flip-down-back 300ms ease-in both;
	}
	
	&.under {
		animation: fade-under 300ms ease-in both;
	}
	
}

@keyframes flip-down-front {
	0% {
		transform: rotateX(0deg);
		background-color: $flipColour;
		color: $textColour;
	}
	100% {
		transform: rotateX(-180deg);
		background-color: $flipColourDark;
		color: $textColourDark;
	}
}

@keyframes flip-down-back {
	0% {
		transform: rotateY(180deg) rotateX(0deg);
		background-color: $flipColourDark;
		color: $textColourDark;
	}
	100% {
		transform: rotateY(180deg) rotateX(180deg);
		background-color: $flipColour;
		color: $textColour;
	}
}

@keyframes fade-under {
	0% {
		background-color: $flipColourDark;
		color: $textColourDark;
	}
	100% {
		background-color: $flipColour;
		color: $textColour;
	}
}

.clock {
	position: absolute;
	width: 70vw;
	top: 50%;
	left: 15vw;
	transform: translateY(-50%);
	perspective: 100vw;
	perspective-origin: 50% 50%;
	
	.digit {
		margin-right: 1vw;
		&:nth-child(2n+2) { margin-right: 3.5vw; }
		&:last-child { margin-right: 0; }
	}
	
}  

            
          
!
            
              function flipTo(digit, n){
	var current = digit.attr('data-num');
	digit.attr('data-num', n);
	digit.find('.front').attr('data-content', current);
	digit.find('.back, .under').attr('data-content', n);
	digit.find('.flap').css('display', 'block');
	setTimeout(function(){
		digit.find('.base').text(n);
		digit.find('.flap').css('display', 'none');
	}, 350);
}

function jumpTo(digit, n){
	digit.attr('data-num', n);
	digit.find('.base').text(n);
}

function updateGroup(group, n, flip){
	var digit1 = $('.ten'+group);
	var digit2 = $('.'+group);
	n = String(n);
	if(n.length == 1) n = '0'+n;
	var num1 = n.substr(0, 1);
	var num2 = n.substr(1, 1);
	if(digit1.attr('data-num') != num1){
		if(flip) flipTo(digit1, num1);
		else jumpTo(digit1, num1);
	}
	if(digit2.attr('data-num') != num2){
		if(flip) flipTo(digit2, num2);
		else jumpTo(digit2, num2);
	}
}

function setTime(flip){
	var t = new Date();
	updateGroup('hour', t.getHours(), flip);
	updateGroup('min', t.getMinutes(), flip);
	updateGroup('sec', t.getSeconds(), flip);
}

$(document).ready(function(){
	
	setTime(false);
	setInterval(function(){
		setTime(true);
	}, 1000);
	
});
            
          
!
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