//note: the example makes use of ES6 methods and syntax
const data = {
Europe: {
France: ["Paris", "Lyon", "Cannes", "Saint-Tropez", "Marseille", "Avignon"],
Poland:["Warschau"],
Croatia:["Zagreb"],
Germany: ["Berlin","Hamburg"],
Spain:["Madrid", "Barcelona"],
Ireland: ["Dublin"]
},
Asia: {
Japan: ["Tokyo"]
},
"North and Central America":{
},
Africa:{
},
"South America":{
},
"Australia and Oceani":{
}
};
const sides = [...document.querySelectorAll('div.side')]; //get a reference to all side divs (another option would be to generate the html dynamically)
let cur = {props : [], obj:data}; //active object
function set(obj){ //sets 'curprops' and fills the sides with the appropiate text
cur.obj = obj || data; //if obj is null, end of the line is reached and initial 'data' is used
cur.props = Array.isArray(cur.obj) ? cur.obj : Object.getOwnPropertyNames(cur.obj);
for(let i=0; i < sides.length; i++){ //set the text of each side
sides[i].querySelector('.table-cell').textContent = i < cur.props.length ? cur.props[i] : ''; //the check if i < the number of props might be redundant if all values are guaranteed to have (at least) 6 values, but otherwise empties all other sides
}
}
set(); //first call to set the initial values
for(let i=0;i<6;i++) //bind each side to its own click event (note 'let' instead of 'var' is important here)
sides[i].onclick = function(){
set(cur.obj[cur.props[i]]);
}
body {
background-color: darkkhaki;
}
.side {
float:left;
position: relative;
width: calc(100%/ 7);
margin: 1%;
padding-bottom: calc(100% / 7);
background-color: none;
overflow:hidden;
border: 2px solid gray;
}
.content {
position: absolute;
height: 90%;
width: 90%;
padding: 5%;
}
.table {
display: table;
width: 100%;
height: 100%;
}
.table-cell {
display: table-cell;
vertical-align: middle;
text-align: center;
color: white;
font-family: Verdana;
font-size: 2em;
font-weight: bold;
}
.one {
position: absolute;
top: 0%;
right: 0%;
width: 20%;
height: 20%;
background-color: gray;
overflow: hidden;
display: table;
}
.dice {
display: table-cell;
color: white;
font-family: Verdana;
font-size: 250%;
vertical-align: middle;
text-align: center;
font-weight: bold;
}
<div id= "overlay">
<div class="side">
<div class="content">
<div class="table">
<div class="table-cell"></div>
<div class="one"><div class="dice">1</div></div>
</div>
</div>
</div>
<div class="side">
<div class="content">
<div class="table">
<div class="table-cell"></div>
<div class="one"><div class="dice">2</div></div>
</div>
</div>
</div>
<div class="side">
<div class="content">
<div class="table">
<div class="table-cell"></div>
<div class="one"><div class="dice">3</div></div>
</div>
</div>
</div>
<div class="side">
<div class="content">
<div class="table">
<div class="table-cell"></div>
<div class="one"><div class="dice">4</div></div>
</div>
</div>
</div>
<div class="side">
<div class="content">
<div class="table">
<div class="table-cell"></div>
<div class="one"><div class="dice">5</div></div>
</div>
</div>
</div>
<div class="side">
<div class="content">
<div class="table">
<div class="table-cell"></div>
<div class="one"><div class="dice">6</div></div>
</div>
</div>
</div>
</div>