Vielen Dank für all die Rückmeldungen.
Ich habe die Beiträge eingebaut.
Jetzt habe ich jedoch das Problem, dass das onclick-Ereignis nicht funktioniert.
Wenn ich auf den Vertikalen Link klicke, dann wird das onclick-Ereignis nicht ausgelöst.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Single Page App</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body>
<aside>
<ul class="nav_vertical">
<li id="first"><a href="#erste"><span class="material-icons">photo_library</span></a></li>
<li id="second"><a href="#zweite"><span class="material-icons">photo_library</span></a></li>
<li id="third"><a href="#dritte"><span class="material-icons">question_answer</span></a></li>
</ul>
</aside>
<section>
<ul id="erste" class="nav_horizontal">
<li class="link-top"><a href="#1.1">1.1</a></li>
<li class="link-top"><a href="#1.2">1.2</a></li>
<li class="link-top"><a href="#1.3">1.3</a></li>
</ul>
<ul id="zweite" class="nav_horizontal">
<li class="link-top"><a href="#2.1">2.1</a></li>
<li class="link-top"><a href="#2.2">2.2</a></li>
<li class="link-top"><a href="#2.3">2.3</a></li>
</ul>
<ul id="dritte" class="nav_horizontal">
<li class="link-top"><a href="#3.1">3.1</a></li>
<li class="link-top"><a href="#3.2">3.2</a></li>
<li class="link-top"><a href="#3.3">3.3</a></li>
</ul>
</section>
<article>
<p>Content</p>
</article>
<script src="app.js" type="module"></script>
</body>
</html>
Alles anzeigen
CSS-Datei: style.css
* {
font-family: sans-serif;
}
ul {
list-style-type: none;
}
@media screen and (min-width: 50em) {
body {
padding: 0px;
margin: 0px;
height: 100vh;
display: grid;
grid-template-rows: 0.2fr 10fr;
grid-template-columns: 0.2fr 10fr;
grid-template-areas:
"aside section"
"aside article"
}
}
section{
grid-area: section;
background: lightsalmon;
}
aside {
grid-area: aside;
top: 0px;
display: flex;
align-items: center;
flex-direction: column;
background: #009879;
border-right: 2px solid #008C71;
box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.25);
list-style-type: none;
}
article {
grid-area: article;
background: lightcyan;
}
.nav_vertical {
display: flex;
align-items: center;
flex-direction: column;
background: #008C71;
border-bottom: 1px solid #009879;
list-style-type: none;
padding: 10px;
}
.nav_vertical .material-icons {
float: left;
color: #ffffff;
padding: 10px;
}
.nav_horizontal {
list-style-type: none;
padding: 10px;
}
.nav_horizontal li {
float: left;
width: 50px;
}
.link-top{
float: left;
width: 150px;
list-style-type: none;
}
.link-top a{
text-decoration: none;
}
Alles anzeigen
Javascript: app.js
window.onload = function () {
"use strict";
const verticalElememts = document.querySelector(".nav_vertical").children;
const verticals = Array.from(verticalElememts);
const horizontals = document.querySelectorAll('.nav_horizontal');
document.getElementById("first").onclick = showHorizontal("first", "erste");
document.getElementById("second").onclick = showHorizontal("second", "zweite");
document.getElementById("third").onclick = showHorizontal("third", "dritte");
function showHorizontal(left, top) {
verticals.forEach(item => {
if (item.id == left) {
item.style.background = "#9ef007"
} else {
item.style.background = "#008C71";
}
});
horizontals.forEach(item => {
if (item.id == top) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
}
showHorizontal("first", "erste");
}
Alles anzeigen
Die folgenden 3 Zeilen aus der app.js werden nicht beachtet:
document.getElementById("first").onclick = showHorizontal("first", "erste");
document.getElementById("second").onclick = showHorizontal("second", "zweite");
document.getElementById("third").onclick = showHorizontal("third", "dritte");
Hat jemand eine Idee warum diese Zeilen nicht beachtet werden