Skip to content

Instantly share code, notes, and snippets.

@veltman
Last active Jul 3, 2016
Embed
What would you like to do?
Mystery box #2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
body {
margin: 0;
padding: 0;
}
.container {
width: 300px;
height: 500px;
margin: 100px auto 0 auto;
position: relative;
perspective: 2000px;
-webkit-perspective: 2000px;
}
.cube {
position: absolute;
width: 100%;
height: 100%;
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
animation: spin 5s infinite linear;
-webkit-animation: spin 5s infinite linear;
}
.questionmark {
position: absolute;
width: 300px;
height: 300px;
pointer-events: none;
background: url("data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjExOSIgaGVpZ2h0PSIxMTQiPgo8cGF0aCBmaWxsPSIjRkZGRkZGIiBzdHJva2U9IiMwMEE2RTAiIHN0cm9rZS13aWR0aD0iOCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBkPSJNNi4xLDQ1TDMxLDUuNkw5NC4yLDYuNUwxMTMsNTIuOAoJTDgwLjMsNjdMODAuNSw3Ni4xTDUwLjYsNzYuNkw1MC44LDU2LjZMNjkuOCw0Mi44TDcyLjYsMzkuOUw0OC4yLDM2LjZMNDAuMiw2My41WiI+PC9wYXRoPgo8cGF0aCBmaWxsPSIjRkZGRkZGIiBzdHJva2U9IiMwMEE2RTAiIHN0cm9rZS13aWR0aD0iOCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBkPSJNNDkuNiwxMTAuM0w4Mi45LDExMC4yTDgwLjcsODMuMgoJNTAuMyw4My40WiI+PC9wYXRoPgo8L3N2Zz4=") no-repeat center center;
background-size: 178px 171px;
animation: spin 5s infinite linear reverse;
-webkit-animation: spin 5s infinite linear reverse;
}
.side {
margin: 0;
width: 300px;
height: 300px;
position: absolute;
cursor: pointer;
}
.side > * {
border: 0;
display: block;
position: absolute;
width: 100%;
height: 100%;
}
iframe {
opacity: 0;
overflow: hidden;
}
.hidden {
display: none;
}
.side > div {
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MCIgaGVpZ2h0PSI1MCI+CjxyZWN0IGZpbGw9InJnYmEoMjU1LDI1NSwyNTUsMC4yKSIgc3Ryb2tlPSJub25lIiB4PSIwIiB5PSIwIiB3aWR0aD0iMjUiIGhlaWdodD0iMjUiPjwvcmVjdD4Kd2lkdGg9JzUwJyBoZWlnaHQ9JzUwJyZndDsKPHJlY3QgZmlsbD0icmdiYSgyNTUsMjU1LDI1NSwwLjIpIiBzdHJva2U9Im5vbmUiIHg9IjI1IiB5PSIyNSIgd2lkdGg9IjI1IiBoZWlnaHQ9IjI1Ij48L3JlY3Q+Cjwvc3ZnPg==");
pointer-events: none;
}
.cube {
transform: translateZ(-100px) rotateX(-90deg);
-webkit-transform: translateZ(-100px) rotateX(-90deg);
}
.front {
transform: rotateX(-12deg) rotateY(45deg) translateZ(150px);
animation: fade 5s infinite linear -1.25s;
-webkit-animation: fade 5s infinite linear -1.25s;
}
.back {
transform: rotateX(168deg) rotateY(-45deg) rotateZ(180deg) translateZ(150px);
animation: fade 5s infinite linear -3.75s;
-webkit-animation: fade 5s infinite linear -3.75s;
}
.right {
transform: rotateX(-12deg) rotateY(135deg) translateZ(150px);
animation: fade 5s infinite linear;
-webkit-animation: fade 5s infinite linear;
}
.left {
transform: rotateX(-12deg) rotateY(-45deg) translateZ(150px);
animation: fade 5s infinite linear -2.5s;
-webkit-animation: fade 5s infinite linear -2.5s;
}
.top {
transform: rotateX(78deg) rotateZ(-45deg) translateZ(150px);
}
.bottom {
transform: rotateX(-102deg) rotateZ(45deg) translateZ(150px);
}
.front > div {
background-color: rgba(44,155,222,0.6);
}
.back > div {
background-color: rgba(43,236,136,0.6);
}
.right > div {
background-color: rgba(153,242,87,0.6);
}
.left > div {
background-color: rgba(255,135,58,0.6);
}
.top > div {
background-color: rgba(239,67,148,0.6);
}
.bottom > div {
background-color: rgba(115,63,172,0.6);
}
@keyframes fade {
from { opacity: 1; }
12.5% { opacity: 0.3; }
62.5% { opacity: 0.3; }
75% { opacity: 1; }
}
@-webkit-keyframes fade {
from { opacity: 1; }
12.5% { opacity: 0.3; }
62.5% { opacity: 0.3; }
75% { opacity: 1; }
}
@keyframes spin {
from { transform: rotateY(0deg); }
to { transform: rotateY(-360deg); }
}
@-webkit-keyframes spin {
from { -webkit-transform: rotateY(0deg); }
to { -webkit-transform: rotateY(-360deg); }
}
</style>
</head>
<body>
<div class="container">
<div class="cube">
<div class="side top"><div></div></div>
<div class="side front"><div></div></div>
<div class="side back"><div></div></div>
<div class="side right"><div></div></div>
<div class="side left"><div></div></div>
<div class="side bottom"><div></div></div>
<div class="questionmark"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script>
<script>
var user = "tophtucker";
d3.json("https://api.github.com/users/" + user + "/gists",function(err, gists){
gists = gists.filter(function(gist){
return gist.files && gist.files["index.html"];
}).map(function(gist){
return "//bl.ocks.org/" + user + "/raw/" + gist.id;
});
d3.shuffle(gists);
var sides = d3.selectAll(".side");
sides.append("iframe")
.attr("marginwidth", 0)
.attr("marginheight", 0)
.attr("scrolling", "no");
sides.append("a")
.attr("class", "hidden")
.attr("target", "_blank");
sides.transition()
.delay(function(d,i){
return i * 2500;
})
.each("end", mystery);
function mystery() {
var next = gists[gists.push(gists.shift()) - 1];
var side = d3.select(this),
iframe = side.select("iframe"),
link = side.select("a");
link.classed("hidden", false)
.attr("href", next);
side.select("iframe")
.on("load",function(){
d3.select(this)
.transition()
.duration(100)
.style("opacity", 1)
.transition()
.delay(Math.random() * 7500 + 7500)
.duration(100)
.style("opacity", 0)
.each("end",function(){
link.classed("hidden", true)
.attr("href", null);
side.transition()
.delay(3000)
.each("end", mystery);
});
})
.attr("src", next);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment