Hopefully this solution is helpful. It took me quite a few hours to figure it out, even after searching extensively on stackoverflow.
<!DOCTYPE html>
<html>
<title>Creating Menu Animation with JavaScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#navi{
position: absolute;
top: 40px;
left: 3%;
width: 25%;
}
.menuItem{
margin-bottom: 5px;
width: 100%;
}
.menuPage{
border: 1px solid #000000;
background-color: #dcdcdc;
text-align: center;
padding: 2px 4px;
}
</style>
<body>
<div id="navi">
<div id="Ldon" class="menuItem" onclick="openCity('London', 'Ldon')"><p class="menuPage">London</p>
<div id="London" class="city" style="display:none">
<h2>London</h2>
<p>London is the capital city of England.</p>
</div>
</div>
<div id="Pris" class="menuItem" onclick="openCity('Paris', 'Pris')"><p class="menuPage">Paris</p>
<div id="Paris" class="city" style="display:none">
<h2>Paris</h2>
<p>Paris is the capital of France.</p>
</div>
</div>
<div id="Tkyo" class="menuItem" onclick="openCity('Tokyo', 'Tkyo')"><p class="menuPage">Tokyo</p>
<div id="Tokyo" class="city" style="display:none">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>
</div>
</div>
</div>
<script>
function openCity(cityName, newPos) {
var i;
var y = document.getElementsByClassName("menuItem");
var x = document.getElementsByClassName("city");
var movePos = document.getElementById(newPos);
for (i = 0; i < y.length; i++) {
y[i].style.position = "";
y[i].style.top = "";
}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
document.getElementById(cityName).style.display = "block";
movePos.style.position = "absolute";
movePos.style.top = "80px";
}
</script>
</body>
</html>