JSFiddle - React, Tailwind, and code Playground
by Nick Karnik
HTML
<script src="http://workshop.chromeexperiments.com/globe/globe.js"></script>
<script src="http://workshop.chromeexperiments.com/globe/third-party/Three/Detector.js"></script>
<script src="http://workshop.chromeexperiments.com/globe/third-party/Three/RequestAnimationFrame.js"></script>
<script src="https://rawgithub.com/mrdoob/three.js/master/build/three.js"></script>
<script src="http://workshop.chromeexperiments.com/globe/third-party/Three/ThreeExtras.js"></script>
<script src="http://workshop.chromeexperiments.com/globe/third-party/Three/ThreeWebGL.js"></script>
<script src="http://workshop.chromeexperiments.com/globe/third-party/Tween.js"></script>
<div id="container"></div>
<div id="info">
<strong><a href="http://www.chromeexperiments.com/globe">WebGL Globe</a></strong> <span class="bull">•</span>Â Created by the Google Data Arts Team <span class="bull">•</span> Data acquired from <a href="http://sedac.ciesin.columbia.edu/gpw/">SEDAC</a>
</div>
<div id="currentInfo">
<span id="year1990" class="year">1990</span>
<span id="year1995" class="year">1995</span>
<span id="year2000" class="year">2000</span>
</div>
<div id="title">
World Population
</div>
<a id="ce" href="http://www.chromeexperiments.com/globe">
<span>This is a Chrome Experiment</span>
</a>
CSS
html {
height: 100%;
}
body {
margin: 0;
padding: 0;
background: #000000 url(/globe/loading.gif) center center no-repeat;
color: #ffffff;
font-family: sans-serif;
font-size: 13px;
line-height: 20px;
height: 100%;
}
#info {
font-size: 11px;
position: absolute;
bottom: 5px;
background-color: rgba(0,0,0,0.8);
border-radius: 3px;
right: 10px;
padding: 10px;
}
#currentInfo {
width: 270px;
position: absolute;
left: 20px;
top: 63px;
background-color: rgba(0,0,0,0.2);
border-top: 1px solid rgba(255,255,255,0.4);
padding: 10px;
}
a {
color: #aaa;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.bull {
padding: 0 5px;
color: #555;
}
#title {
position: absolute;
top: 20px;
width: 270px;
left: 20px;
background-color: rgba(0,0,0,0.2);
border-radius: 3px;
font: 20px Georgia;
padding: 10px;
}
.year {
font: 16px Georgia;
line-height: 26px;
height: 30px;
text-align: center;
float: left;
width: 90px;
color: rgba(255, 255, 255, 0.4);
cursor: pointer;
-webkit-transition: all 0.1s ease-out;
}
.year:hover, .year.active {
font-size: 23px;
color: #fff;
}
#ce span {
display: none;
}
#ce {
width: 107px;
height: 55px;
display: block;
position: absolute;
bottom: 15px;
left: 20px;
background: url(/globe/ce.png);
}
JavaScript
if(!Detector.webgl){
Detector.addGetWebGLMessage();
} else {
var years = ['1990','1995','2000'];
var container = document.getElementById('container');
var globe = new DAT.Globe(container);
console.log(globe);
var i, tweens = [];
var settime = function(globe, t) {
return function() {
new TWEEN.Tween(globe).to({time: t/years.length},500).easing(TWEEN.Easing.Cubic.EaseOut).start();
var y = document.getElementById('year'+years[t]);
if (y.getAttribute('class') === 'year active') {
return;
}
var yy = document.getElementsByClassName('year');
for(i=0; i<yy.length; i++) {
yy[i].setAttribute('class','year');
}
y.setAttribute('class', 'year active');
};
};
for(var i = 0; i<years.length; i++) {
var y = document.getElementById('year'+years[i]);
y.addEventListener('mouseover', settime(globe,i), false);
}
var xhr;
TWEEN.start();
xhr = new XMLHttpRequest();
xhr.open('GET', '/globe/population909500.json', true);
xhr.onreadystatechange = function(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
window.data = data;
for (i=0;i<data.length;i++) {
globe.addData(data[i][1], {format: 'magnitude', name: data[i][0], animated: true});
}
globe.createPoints();
settime(globe,0)();
globe.animate();
}
}
};
xhr.send(null);
}