1396 lines
49 KiB
HTML
1396 lines
49 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="de">
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>JavaScript Lernplattform – CodeLernen</title>
|
||
|
||
<style>
|
||
/* Kopfzeile bleibt beim Scrollen oben sichtbar */
|
||
header {
|
||
background: var(--card);
|
||
border-bottom: 1px solid var(--border);
|
||
padding: 20px;
|
||
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 1000;
|
||
}
|
||
|
||
|
||
|
||
|
||
/* ==================================================
|
||
PFEIL: ZURÜCK NACH OBEN
|
||
================================================== */
|
||
|
||
#backToTop {
|
||
position: fixed;
|
||
right: 25px;
|
||
bottom: 25px;
|
||
|
||
width: 48px;
|
||
height: 48px;
|
||
|
||
border: none;
|
||
border-radius: 50%;
|
||
|
||
background: var(--primary);
|
||
color: white;
|
||
|
||
font-size: 26px;
|
||
cursor: pointer;
|
||
|
||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||
z-index: 2000;
|
||
|
||
/* Anfangs ist der Pfeil versteckt */
|
||
opacity: 0;
|
||
visibility: hidden;
|
||
transform: translateY(10px);
|
||
|
||
transition:
|
||
opacity 0.25s,
|
||
visibility 0.25s,
|
||
transform 0.25s;
|
||
}
|
||
|
||
/* Pfeil sichtbar machen */
|
||
#backToTop.visible {
|
||
opacity: 1;
|
||
visibility: visible;
|
||
transform: translateY(0);
|
||
}
|
||
|
||
/* Effekt beim Darüberfahren */
|
||
#backToTop:hover {
|
||
opacity: 0.85;
|
||
}
|
||
|
||
/* Tastaturfokus sichtbar machen */
|
||
#backToTop:focus-visible {
|
||
outline: 3px solid var(--text);
|
||
outline-offset: 3px;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
:root {
|
||
--bg: #f3f5fb;
|
||
--card: #fff;
|
||
--text: #202438;
|
||
--muted: #6b7280;
|
||
--primary: #6258dc;
|
||
--border: #dfe3ee;
|
||
--success: #16845b;
|
||
--danger: #d93650;
|
||
}
|
||
|
||
body.dark {
|
||
--bg: #171925;
|
||
--card: #222536;
|
||
--text: #f5f5fa;
|
||
--muted: #b8bdd0;
|
||
--primary: #938aff;
|
||
--border: #3b3f54;
|
||
--success: #54d6a0;
|
||
--danger: #ff7588;
|
||
}
|
||
|
||
* {
|
||
box-sizing: border-box;
|
||
margin: 0;
|
||
padding: 0
|
||
}
|
||
|
||
body {
|
||
font-family: Arial, sans-serif;
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
line-height: 1.6;
|
||
transition: background .2s, color .2s;
|
||
}
|
||
|
||
button,
|
||
input,
|
||
select,
|
||
textarea {
|
||
font: inherit
|
||
}
|
||
|
||
button {
|
||
cursor: pointer
|
||
}
|
||
|
||
.container {
|
||
width: min(1100px, 92%);
|
||
margin: auto
|
||
}
|
||
|
||
header {
|
||
background: var(--card);
|
||
border-bottom: 1px solid var(--border);
|
||
padding: 18px 0
|
||
}
|
||
|
||
.header-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 12px
|
||
}
|
||
|
||
.logo {
|
||
color: var(--primary);
|
||
font-weight: bold;
|
||
font-size: 23px
|
||
}
|
||
|
||
nav {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
margin-top: 14px
|
||
}
|
||
|
||
nav a {
|
||
text-decoration: none;
|
||
color: var(--text);
|
||
padding: 6px 10px;
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px
|
||
}
|
||
|
||
nav a:hover {
|
||
color: var(--primary)
|
||
}
|
||
|
||
main {
|
||
padding: 30px 0
|
||
}
|
||
|
||
.intro {
|
||
margin-bottom: 24px
|
||
}
|
||
|
||
.intro h1 {
|
||
font-size: clamp(26px, 4vw, 36px);
|
||
margin-bottom: 8px
|
||
}
|
||
|
||
.muted {
|
||
color: var(--muted)
|
||
}
|
||
|
||
.grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||
gap: 18px
|
||
}
|
||
|
||
.card {
|
||
background: var(--card);
|
||
border: 1px solid var(--border);
|
||
border-radius: 14px;
|
||
padding: 20px;
|
||
min-width: 0
|
||
}
|
||
|
||
.card h2 {
|
||
margin-bottom: 12px;
|
||
font-size: 20px
|
||
}
|
||
|
||
.full {
|
||
grid-column: 1/-1
|
||
}
|
||
|
||
.section-number {
|
||
color: var(--primary);
|
||
font-size: 12px;
|
||
font-weight: bold;
|
||
margin-bottom: 5px
|
||
}
|
||
|
||
.btn {
|
||
background: var(--primary);
|
||
color: white;
|
||
border: none;
|
||
padding: 10px 14px;
|
||
border-radius: 8px;
|
||
margin: 3px 2px
|
||
}
|
||
|
||
.btn:hover {
|
||
filter: brightness(1.1)
|
||
}
|
||
|
||
.secondary {
|
||
background: transparent;
|
||
color: var(--text);
|
||
border: 1px solid var(--border)
|
||
}
|
||
|
||
.danger {
|
||
background: var(--danger)
|
||
}
|
||
|
||
.form-group {
|
||
margin-bottom: 12px
|
||
}
|
||
|
||
label {
|
||
display: block;
|
||
font-weight: bold;
|
||
margin-bottom: 5px
|
||
}
|
||
|
||
input,
|
||
select,
|
||
textarea {
|
||
width: 100%;
|
||
padding: 10px;
|
||
background: var(--card);
|
||
color: var(--text);
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px
|
||
}
|
||
|
||
input[type=checkbox] {
|
||
width: auto
|
||
}
|
||
|
||
input:focus,
|
||
select:focus,
|
||
textarea:focus {
|
||
outline: 2px solid var(--primary)
|
||
}
|
||
|
||
.input-row {
|
||
display: flex;
|
||
gap: 8px
|
||
}
|
||
|
||
.input-row input {
|
||
flex: 1;
|
||
min-width: 0
|
||
}
|
||
|
||
.message {
|
||
margin-top: 10px;
|
||
min-height: 24px;
|
||
font-weight: bold
|
||
}
|
||
|
||
.success {
|
||
color: var(--success)
|
||
}
|
||
|
||
.error {
|
||
color: var(--danger)
|
||
}
|
||
|
||
ul {
|
||
list-style: none
|
||
}
|
||
|
||
.list-item {
|
||
padding: 10px 0;
|
||
border-bottom: 1px solid var(--border)
|
||
}
|
||
|
||
.list-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
gap: 10px
|
||
}
|
||
|
||
.tag {
|
||
font-size: 12px;
|
||
color: var(--primary);
|
||
background: var(--bg);
|
||
padding: 3px 8px;
|
||
border-radius: 20px
|
||
}
|
||
|
||
.task-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
min-width: 0
|
||
}
|
||
|
||
.task-left span {
|
||
overflow-wrap: anywhere
|
||
}
|
||
|
||
.completed span {
|
||
text-decoration: line-through;
|
||
color: var(--muted)
|
||
}
|
||
|
||
.tab-buttons {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
margin-bottom: 12px
|
||
}
|
||
|
||
.tab-button {
|
||
background: transparent;
|
||
color: var(--text);
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 8px 12px
|
||
}
|
||
|
||
.tab-button.active {
|
||
background: var(--primary);
|
||
color: white
|
||
}
|
||
|
||
.tab-panel {
|
||
display: none;
|
||
padding: 14px;
|
||
background: var(--bg);
|
||
border-radius: 8px
|
||
}
|
||
|
||
.tab-panel.active {
|
||
display: block
|
||
}
|
||
|
||
pre,
|
||
.output {
|
||
white-space: pre-wrap;
|
||
overflow-wrap: anywhere;
|
||
background: var(--bg);
|
||
padding: 12px;
|
||
border-radius: 8px;
|
||
margin: 10px 0
|
||
}
|
||
|
||
.table-wrap {
|
||
overflow-x: auto
|
||
}
|
||
|
||
table {
|
||
width: 100%;
|
||
border-collapse: collapse
|
||
}
|
||
|
||
th,
|
||
td {
|
||
text-align: left;
|
||
padding: 9px;
|
||
border-bottom: 1px solid var(--border)
|
||
}
|
||
|
||
th {
|
||
background: var(--bg)
|
||
}
|
||
|
||
.accordion-button {
|
||
display: block;
|
||
width: 100%;
|
||
text-align: left;
|
||
padding: 11px;
|
||
margin: 5px 0;
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
background: var(--card);
|
||
color: var(--text)
|
||
}
|
||
|
||
.accordion-content {
|
||
display: none;
|
||
background: var(--bg);
|
||
padding: 12px;
|
||
border-radius: 8px
|
||
}
|
||
|
||
.accordion-content.open {
|
||
display: block
|
||
}
|
||
|
||
.modal {
|
||
display: none;
|
||
position: fixed;
|
||
inset: 0;
|
||
z-index: 100;
|
||
background: #000a;
|
||
justify-content: center;
|
||
align-items: center;
|
||
padding: 20px
|
||
}
|
||
|
||
.modal.open {
|
||
display: flex
|
||
}
|
||
|
||
.modal-content {
|
||
background: var(--card);
|
||
padding: 24px;
|
||
border-radius: 12px;
|
||
width: min(450px, 100%)
|
||
}
|
||
|
||
.toast-container {
|
||
position: fixed;
|
||
right: 15px;
|
||
bottom: 15px;
|
||
z-index: 200;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px
|
||
}
|
||
|
||
.toast {
|
||
color: white;
|
||
background: #30344a;
|
||
padding: 12px 16px;
|
||
border-radius: 8px;
|
||
max-width: 300px
|
||
}
|
||
|
||
.toast.success {
|
||
background: #16845b
|
||
}
|
||
|
||
.toast.error {
|
||
background: #c92f49
|
||
}
|
||
|
||
.progress-track {
|
||
height: 12px;
|
||
background: var(--border);
|
||
border-radius: 20px;
|
||
overflow: hidden;
|
||
margin: 10px 0
|
||
}
|
||
|
||
.progress-bar {
|
||
width: 0;
|
||
height: 100%;
|
||
background: var(--primary);
|
||
transition: width .2s
|
||
}
|
||
|
||
.big-number {
|
||
font-size: 35px;
|
||
font-weight: bold;
|
||
margin: 10px 0
|
||
}
|
||
|
||
.animation-box {
|
||
width: 50px;
|
||
height: 50px;
|
||
border-radius: 10px;
|
||
background: var(--primary);
|
||
margin: 15px 0
|
||
}
|
||
|
||
.animation-box.animate {
|
||
animation: moveBox 1s ease
|
||
}
|
||
|
||
@keyframes moveBox {
|
||
0% {
|
||
transform: translateX(0) rotate(0)
|
||
}
|
||
|
||
50% {
|
||
transform: translateX(140px) rotate(180deg)
|
||
}
|
||
|
||
100% {
|
||
transform: translateX(0) rotate(360deg)
|
||
}
|
||
}
|
||
|
||
footer {
|
||
text-align: center;
|
||
padding: 25px 0;
|
||
color: var(--muted)
|
||
}
|
||
|
||
@media(max-width:700px) {
|
||
.grid {
|
||
grid-template-columns: 1fr
|
||
}
|
||
|
||
.full {
|
||
grid-column: auto
|
||
}
|
||
|
||
.card {
|
||
padding: 16px
|
||
}
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
|
||
<!-- Pfeil zum Zurückscrollen nach oben -->
|
||
<button id="backToTop" type="button" aria-label="Zurück nach oben" title="Zurück nach oben">
|
||
↑
|
||
</button>
|
||
|
||
<body>
|
||
<header>
|
||
<div class="container">
|
||
<div class="header-row">
|
||
<div class="logo">CodeLernen</div>
|
||
<div>
|
||
<button class="btn secondary" id="themeButton">Dark Mode</button>
|
||
<button class="btn" id="openModalButton">Hilfe</button>
|
||
</div>
|
||
</div>
|
||
<nav>
|
||
<a href="#login">Login</a>
|
||
<a href="#suche">Suche</a>
|
||
<a href="#filter">Filter</a>
|
||
<a href="#aufgaben">Aufgaben</a>
|
||
<a href="#arrays">Arrays</a>
|
||
<a href="#spiele">Spiele</a>
|
||
<a href="#daten">Daten</a>
|
||
<a href="#code">Codebeispiele</a>
|
||
</nav>
|
||
</div>
|
||
</header>
|
||
|
||
<main class="container">
|
||
<section class="intro">
|
||
<h1>HTML, CSS und JavaScript</h1>
|
||
<p class="muted">Eine kommentierte Sammlung von Beispielen zum Lernen und Üben.</p>
|
||
</section>
|
||
|
||
<div class="grid">
|
||
|
||
<section class="card" id="login">
|
||
<div class="section-number">BEISPIEL 01</div>
|
||
<h2>Login und Formularprüfung</h2>
|
||
<form id="loginForm">
|
||
<div class="form-group">
|
||
<label for="username">Benutzername</label>
|
||
<input id="username" type="text" placeholder="Name">
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="password">Passwort</label>
|
||
<div class="input-row">
|
||
<input id="password" type="password" placeholder="Mindestens 4 Zeichen">
|
||
<button class="btn secondary" id="togglePassword" type="button">Anzeigen</button>
|
||
</div>
|
||
</div>
|
||
<button class="btn" type="submit">Anmelden</button>
|
||
<p id="loginMessage" class="message"></p>
|
||
</form>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 02</div>
|
||
<h2>Klickzähler</h2>
|
||
<div class="big-number" id="clickCount">0</div>
|
||
<button class="btn" id="countButton">Klick mich</button>
|
||
<button class="btn secondary" id="resetCountButton">Zurücksetzen</button>
|
||
</section>
|
||
|
||
<section class="card" id="suche">
|
||
<div class="section-number">BEISPIEL 03</div>
|
||
<h2>Live-Suche</h2>
|
||
<input id="searchInput" type="text" placeholder="Name oder Thema suchen">
|
||
<ul id="peopleList">
|
||
<li class="list-item">
|
||
<div class="list-row"><span>Anna Müller</span><span class="tag">HTML</span></div>
|
||
</li>
|
||
<li class="list-item">
|
||
<div class="list-row"><span>Max Berger</span><span class="tag">CSS</span></div>
|
||
</li>
|
||
<li class="list-item">
|
||
<div class="list-row"><span>Lisa Wagner</span><span class="tag">JavaScript</span></div>
|
||
</li>
|
||
<li class="list-item">
|
||
<div class="list-row"><span>Tom Bauer</span><span class="tag">HTML</span></div>
|
||
</li>
|
||
<li class="list-item">
|
||
<div class="list-row"><span>Sarah Hofer</span><span class="tag">JavaScript</span></div>
|
||
</li>
|
||
</ul>
|
||
<p id="searchMessage" class="muted"></p>
|
||
</section>
|
||
|
||
<!-- NEUE FILTERFUNKTION -->
|
||
<section class="card" id="filter">
|
||
<div class="section-number">BEISPIEL 04</div>
|
||
<h2>Lernende filtern</h2>
|
||
<p class="muted">Suche nach Namen und filtere zusätzlich nach Fach.</p>
|
||
|
||
<div class="form-group">
|
||
<label for="filterSearch">Name suchen</label>
|
||
<input id="filterSearch" type="text" placeholder="Zum Beispiel Anna">
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="filterSubject">Fach auswählen</label>
|
||
<select id="filterSubject">
|
||
<option value="alle">Alle Fächer</option>
|
||
<option value="HTML">HTML</option>
|
||
<option value="CSS">CSS</option>
|
||
<option value="JavaScript">JavaScript</option>
|
||
</select>
|
||
</div>
|
||
|
||
<ul id="filterList"></ul>
|
||
<p id="filterResult" class="muted" aria-live="polite"></p>
|
||
</section>
|
||
|
||
<section class="card" id="aufgaben">
|
||
<div class="section-number">BEISPIEL 05</div>
|
||
<h2>Aufgabenliste</h2>
|
||
<div class="input-row">
|
||
<input id="taskInput" type="text" placeholder="Neue Aufgabe">
|
||
<button class="btn" id="addTaskButton">+</button>
|
||
</div>
|
||
<ul id="taskList"></ul>
|
||
<p id="taskCounter" class="muted"></p>
|
||
</section>
|
||
|
||
<section class="card full">
|
||
<div class="section-number">BEISPIEL 06</div>
|
||
<h2>Tabs</h2>
|
||
<div class="tab-buttons">
|
||
<button class="tab-button active" data-tab="htmlTab">HTML</button>
|
||
<button class="tab-button" data-tab="cssTab">CSS</button>
|
||
<button class="tab-button" data-tab="jsTab">JavaScript</button>
|
||
</div>
|
||
<div class="tab-panel active" id="htmlTab">HTML definiert die Struktur einer Website.</div>
|
||
<div class="tab-panel" id="cssTab">CSS gestaltet Farben, Abstände und Layout.</div>
|
||
<div class="tab-panel" id="jsTab">JavaScript macht die Website interaktiv.</div>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 07</div>
|
||
<h2>Taschenrechner</h2>
|
||
<div class="form-group">
|
||
<label for="numberOne">Erste Zahl</label>
|
||
<input id="numberOne" type="number">
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="numberTwo">Zweite Zahl</label>
|
||
<input id="numberTwo" type="number">
|
||
</div>
|
||
<label for="operation">Rechenart</label>
|
||
<select id="operation">
|
||
<option value="add">Addition</option>
|
||
<option value="subtract">Subtraktion</option>
|
||
<option value="multiply">Multiplikation</option>
|
||
<option value="divide">Division</option>
|
||
</select>
|
||
<button class="btn" id="calculateButton">Berechnen</button>
|
||
<p id="calculatorResult" class="message"></p>
|
||
</section>
|
||
|
||
<section class="card" id="spiele">
|
||
<div class="section-number">BEISPIEL 08</div>
|
||
<h2>Würfelspiel</h2>
|
||
<div class="big-number" id="diceNumber">🎲</div>
|
||
<button class="btn" id="rollDiceButton">Würfeln</button>
|
||
<p id="diceMessage" class="message"></p>
|
||
<p id="diceStats" class="muted"></p>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 09</div>
|
||
<h2>Zahl erraten</h2>
|
||
<p>Errate eine Zahl zwischen 1 und 20.</p>
|
||
<input id="guessInput" type="number" min="1" max="20" placeholder="Dein Tipp">
|
||
<button class="btn" id="guessButton">Überprüfen</button>
|
||
<button class="btn secondary" id="newGuessButton">Neues Spiel</button>
|
||
<p id="guessMessage" class="message"></p>
|
||
<p id="guessAttempts" class="muted">Versuche: 0</p>
|
||
</section>
|
||
|
||
<section class="card" id="arrays">
|
||
<div class="section-number">BEISPIEL 10</div>
|
||
<h2>Array-Methoden</h2>
|
||
<label for="arrayOperation">Methode auswählen</label>
|
||
<select id="arrayOperation">
|
||
<option value="show">Alle Zahlen</option>
|
||
<option value="filter">Zahlen über 10</option>
|
||
<option value="map">Zahlen verdoppeln</option>
|
||
<option value="sort">Sortieren</option>
|
||
<option value="sum">Summe</option>
|
||
<option value="find">Erste Zahl über 10</option>
|
||
<option value="max">Größte Zahl</option>
|
||
</select>
|
||
<button class="btn" id="runArrayButton">Ausführen</button>
|
||
<pre id="arrayOutput"></pre>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 11</div>
|
||
<h2>Zahlen sortieren</h2>
|
||
<p>23, 4, 15, 8, 42, 2</p>
|
||
<button class="btn" id="sortAscending">Aufsteigend</button>
|
||
<button class="btn" id="sortDescending">Absteigend</button>
|
||
<button class="btn secondary" id="shuffleNumbers">Mischen</button>
|
||
<div id="sortOutput" class="output">23, 4, 15, 8, 42, 2</div>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 12</div>
|
||
<h2>JavaScript-Objekt</h2>
|
||
<button class="btn" id="showObjectButton">Person anzeigen</button>
|
||
<div class="output" id="objectOutput">Noch keine Person angezeigt.</div>
|
||
</section>
|
||
|
||
<section class="card full" id="daten">
|
||
<div class="section-number">BEISPIEL 13</div>
|
||
<h2>Personentabelle mit Suche</h2>
|
||
<input id="tableSearch" type="text" placeholder="Name oder Beruf suchen">
|
||
<div class="table-wrap">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th>Name</th>
|
||
<th>Alter</th>
|
||
<th>Beruf</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="tableBody"></tbody>
|
||
</table>
|
||
</div>
|
||
<p id="tableResultCount" class="muted"></p>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 14</div>
|
||
<h2>Aufklappbare Bereiche</h2>
|
||
<button class="accordion-button" data-accordion="acc1">Was ist HTML?</button>
|
||
<div class="accordion-content" id="acc1">HTML strukturiert die Inhalte einer Website.</div>
|
||
<button class="accordion-button" data-accordion="acc2">Was ist CSS?</button>
|
||
<div class="accordion-content" id="acc2">CSS gestaltet die Website.</div>
|
||
<button class="accordion-button" data-accordion="acc3">Was ist JavaScript?</button>
|
||
<div class="accordion-content" id="acc3">JavaScript fügt Interaktionen und Logik hinzu.</div>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 15</div>
|
||
<h2>Notizblock</h2>
|
||
<textarea id="noteInput" placeholder="Lernnotiz eingeben..."></textarea>
|
||
<button class="btn" id="saveNoteButton">Speichern</button>
|
||
<button class="btn secondary" id="loadNoteButton">Laden</button>
|
||
<button class="btn danger" id="deleteNoteButton">Löschen</button>
|
||
<p id="noteMessage" class="message"></p>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 16</div>
|
||
<h2>Datum und Uhrzeit</h2>
|
||
<button class="btn" id="showDateButton">Jetzt anzeigen</button>
|
||
<div class="output" id="dateOutput"></div>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 17</div>
|
||
<h2>Text bearbeiten</h2>
|
||
<input id="stringInput" type="text" placeholder="Text eingeben">
|
||
<button class="btn" id="processStringButton">Bearbeiten</button>
|
||
<div class="output" id="stringOutput"></div>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="section-number">BEISPIEL 18</div>
|
||
<h2>CSS-Animation</h2>
|
||
<div class="animation-box" id="animationBox"></div>
|
||
<button class="btn" id="animateButton">Animation starten</button>
|
||
</section>
|
||
|
||
<section class="card full">
|
||
<div class="section-number">BEISPIEL 19</div>
|
||
<h2>Lern-Checkliste</h2>
|
||
<label><input type="checkbox" class="studyCheck"> HTML verstanden</label>
|
||
<label><input type="checkbox" class="studyCheck"> CSS verstanden</label>
|
||
<label><input type="checkbox" class="studyCheck"> Bedingungen verstanden</label>
|
||
<label><input type="checkbox" class="studyCheck"> Schleifen verstanden</label>
|
||
<label><input type="checkbox" class="studyCheck"> Arrays verstanden</label>
|
||
<label><input type="checkbox" class="studyCheck"> DOM verstanden</label>
|
||
<p id="progressText" class="muted">0 von 6 Themen erledigt</p>
|
||
<div class="progress-track">
|
||
<div class="progress-bar" id="progressBar"></div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="card full" id="code">
|
||
<div class="section-number">BEISPIEL 20</div>
|
||
<h2>Codebeispiele zum Lernen</h2>
|
||
<label for="codeSelect">Thema auswählen</label>
|
||
<select id="codeSelect">
|
||
<option value="variable">Variablen</option>
|
||
<option value="condition">if / else</option>
|
||
<option value="function">Funktion</option>
|
||
<option value="event">Event Listener</option>
|
||
<option value="loop">Schleife</option>
|
||
<option value="array">Array</option>
|
||
<option value="filter">filter()</option>
|
||
<option value="map">map()</option>
|
||
<option value="object">Objekt</option>
|
||
<option value="dom">DOM-Element erstellen</option>
|
||
<option value="try">try / catch</option>
|
||
</select>
|
||
<pre><code id="codeDisplay"></code></pre>
|
||
<button class="btn" id="copyCodeButton">Code kopieren</button>
|
||
<p id="copyMessage" class="message"></p>
|
||
</section>
|
||
|
||
</div>
|
||
</main>
|
||
|
||
<div class="modal" id="infoModal">
|
||
<div class="modal-content">
|
||
<h2>Hilfe</h2>
|
||
<p>Suche im Quellcode nach den nummerierten Beispielen.</p>
|
||
<p>HTML baut die Struktur, CSS gestaltet die Website und JavaScript macht sie interaktiv.</p>
|
||
<button class="btn" id="closeModalButton">Schließen</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="toast-container" id="toastContainer"></div>
|
||
|
||
<script>
|
||
// TOAST-NACHRICHTEN
|
||
function showToast(message, type = "success") {
|
||
const toast = document.createElement("div");
|
||
toast.className = "toast " + type;
|
||
toast.textContent = message;
|
||
document.getElementById("toastContainer").appendChild(toast);
|
||
setTimeout(() => toast.remove(), 3000);
|
||
}
|
||
|
||
// DARK MODE
|
||
document.getElementById("themeButton").addEventListener("click", function () {
|
||
document.body.classList.toggle("dark");
|
||
this.textContent = document.body.classList.contains("dark") ? "Light Mode" : "Dark Mode";
|
||
});
|
||
|
||
// LOGIN
|
||
document.getElementById("loginForm").addEventListener("submit", function (event) {
|
||
event.preventDefault();
|
||
const username = document.getElementById("username").value.trim();
|
||
const password = document.getElementById("password").value;
|
||
const message = document.getElementById("loginMessage");
|
||
if (username === "" || password === "") {
|
||
message.textContent = "Bitte alle Felder ausfüllen.";
|
||
message.className = "message error";
|
||
} else if (password.length < 4) {
|
||
message.textContent = "Passwort muss mindestens 4 Zeichen haben.";
|
||
message.className = "message error";
|
||
} else {
|
||
message.textContent = "Hallo " + username + "! Demo-Login erfolgreich.";
|
||
message.className = "message success";
|
||
}
|
||
});
|
||
|
||
// PASSWORT ANZEIGEN
|
||
document.getElementById("togglePassword").addEventListener("click", function () {
|
||
const input = document.getElementById("password");
|
||
if (input.type === "password") {
|
||
input.type = "text"; this.textContent = "Verstecken";
|
||
} else {
|
||
input.type = "password"; this.textContent = "Anzeigen";
|
||
}
|
||
});
|
||
|
||
// KLICKZÄHLER
|
||
let count = Number(localStorage.getItem("learningClickCount") || 0);
|
||
const clickCount = document.getElementById("clickCount");
|
||
function updateClickCount() {
|
||
clickCount.textContent = count;
|
||
localStorage.setItem("learningClickCount", String(count));
|
||
}
|
||
document.getElementById("countButton").addEventListener("click", () => { count++; updateClickCount() });
|
||
document.getElementById("resetCountButton").addEventListener("click", () => { count = 0; updateClickCount() });
|
||
updateClickCount();
|
||
|
||
// LIVE-SUCHE
|
||
const searchInput = document.getElementById("searchInput");
|
||
const people = document.querySelectorAll("#peopleList li");
|
||
function searchPeople() {
|
||
const term = searchInput.value.toLowerCase().trim();
|
||
let visible = 0;
|
||
people.forEach(person => {
|
||
const matches = person.textContent.toLowerCase().includes(term);
|
||
person.style.display = matches ? "" : "none";
|
||
if (matches) visible++;
|
||
});
|
||
document.getElementById("searchMessage").textContent = visible + " Treffer gefunden.";
|
||
}
|
||
searchInput.addEventListener("input", searchPeople);
|
||
searchPeople();
|
||
|
||
// NEUE FILTERFUNKTION
|
||
const lernende = [
|
||
{ name: "Anna", fach: "HTML", alter: 17 },
|
||
{ name: "Max", fach: "CSS", alter: 18 },
|
||
{ name: "Lisa", fach: "JavaScript", alter: 19 },
|
||
{ name: "Tom", fach: "HTML", alter: 16 },
|
||
{ name: "Sarah", fach: "JavaScript", alter: 18 }
|
||
];
|
||
const filterSearch = document.getElementById("filterSearch");
|
||
const filterSubject = document.getElementById("filterSubject");
|
||
const filterList = document.getElementById("filterList");
|
||
const filterResult = document.getElementById("filterResult");
|
||
|
||
function filterLernende() {
|
||
const suchtext = filterSearch.value.toLowerCase().trim();
|
||
const fach = filterSubject.value;
|
||
|
||
// filter() behält nur Personen, die beide Bedingungen erfüllen.
|
||
const gefilterteLernende = lernende.filter(function (person) {
|
||
const namePasst = person.name.toLowerCase().includes(suchtext);
|
||
const fachPasst = fach === "alle" || person.fach === fach;
|
||
return namePasst && fachPasst;
|
||
});
|
||
|
||
filterList.replaceChildren();
|
||
|
||
gefilterteLernende.forEach(function (person) {
|
||
const li = document.createElement("li");
|
||
li.className = "list-item";
|
||
li.textContent = person.name + " – " + person.fach + " – " + person.alter + " Jahre";
|
||
filterList.appendChild(li);
|
||
});
|
||
|
||
filterResult.textContent = gefilterteLernende.length + " Treffer gefunden.";
|
||
}
|
||
filterSearch.addEventListener("input", filterLernende);
|
||
filterSubject.addEventListener("change", filterLernende);
|
||
filterLernende();
|
||
|
||
// AUFGABENLISTE
|
||
const taskInput = document.getElementById("taskInput");
|
||
const taskList = document.getElementById("taskList");
|
||
function updateTaskCounter() {
|
||
const tasks = taskList.querySelectorAll("li").length;
|
||
const completed = taskList.querySelectorAll(".completed").length;
|
||
document.getElementById("taskCounter").textContent = completed + " von " + tasks + " Aufgaben erledigt.";
|
||
}
|
||
function addTask() {
|
||
const text = taskInput.value.trim();
|
||
if (text === "") { showToast("Bitte eine Aufgabe eingeben.", "error"); return; }
|
||
|
||
const li = document.createElement("li");
|
||
li.className = "list-item";
|
||
const row = document.createElement("div");
|
||
row.className = "list-row";
|
||
const left = document.createElement("div");
|
||
left.className = "task-left";
|
||
const checkbox = document.createElement("input");
|
||
checkbox.type = "checkbox";
|
||
const span = document.createElement("span");
|
||
span.textContent = text;
|
||
const deleteButton = document.createElement("button");
|
||
deleteButton.className = "btn danger";
|
||
deleteButton.textContent = "Löschen";
|
||
left.append(checkbox, span);
|
||
row.append(left, deleteButton);
|
||
li.appendChild(row);
|
||
taskList.appendChild(li);
|
||
taskInput.value = "";
|
||
updateTaskCounter();
|
||
}
|
||
document.getElementById("addTaskButton").addEventListener("click", addTask);
|
||
taskInput.addEventListener("keydown", event => { if (event.key === "Enter") addTask() });
|
||
taskList.addEventListener("change", event => {
|
||
if (event.target.type === "checkbox") {
|
||
event.target.closest("li").classList.toggle("completed", event.target.checked);
|
||
updateTaskCounter();
|
||
}
|
||
});
|
||
taskList.addEventListener("click", event => {
|
||
if (event.target.classList.contains("danger")) {
|
||
event.target.closest("li").remove();
|
||
updateTaskCounter();
|
||
}
|
||
});
|
||
|
||
// TABS
|
||
document.querySelectorAll(".tab-button").forEach(button => {
|
||
button.addEventListener("click", () => {
|
||
document.querySelectorAll(".tab-button").forEach(item => item.classList.remove("active"));
|
||
document.querySelectorAll(".tab-panel").forEach(panel => panel.classList.remove("active"));
|
||
button.classList.add("active");
|
||
document.getElementById(button.dataset.tab).classList.add("active");
|
||
});
|
||
});
|
||
|
||
// TASCHENRECHNER
|
||
document.getElementById("calculateButton").addEventListener("click", () => {
|
||
const first = document.getElementById("numberOne").value;
|
||
const second = document.getElementById("numberTwo").value;
|
||
const operation = document.getElementById("operation").value;
|
||
const output = document.getElementById("calculatorResult");
|
||
|
||
if (first.trim() === "" || second.trim() === "") {
|
||
output.textContent = "Bitte beide Zahlen eingeben.";
|
||
output.className = "message error"; return;
|
||
}
|
||
|
||
const a = Number(first), b = Number(second);
|
||
let result;
|
||
switch (operation) {
|
||
case "add": result = a + b; break;
|
||
case "subtract": result = a - b; break;
|
||
case "multiply": result = a * b; break;
|
||
case "divide":
|
||
if (b === 0) {
|
||
output.textContent = "Division durch null ist nicht möglich.";
|
||
output.className = "message error"; return;
|
||
}
|
||
result = a / b; break;
|
||
}
|
||
output.textContent = "Ergebnis: " + result;
|
||
output.className = "message success";
|
||
});
|
||
|
||
// WÜRFELSPIEL
|
||
let diceRolls = 0, sixes = 0;
|
||
document.getElementById("rollDiceButton").addEventListener("click", () => {
|
||
const dice = Math.floor(Math.random() * 6) + 1;
|
||
diceRolls++;
|
||
const message = document.getElementById("diceMessage");
|
||
if (dice === 6) {
|
||
sixes++;
|
||
message.textContent = "Sechs! Du hast gewonnen!";
|
||
message.className = "message success";
|
||
} else {
|
||
message.textContent = "Noch einmal versuchen!";
|
||
message.className = "message";
|
||
}
|
||
document.getElementById("diceNumber").textContent = dice;
|
||
document.getElementById("diceStats").textContent = "Würfe: " + diceRolls + " | Sechsen: " + sixes;
|
||
});
|
||
|
||
// ZAHL ERRATEN
|
||
let secretNumber = Math.floor(Math.random() * 20) + 1;
|
||
let attempts = 0, gameWon = false;
|
||
document.getElementById("guessButton").addEventListener("click", () => {
|
||
const input = document.getElementById("guessInput");
|
||
const guess = Number(input.value);
|
||
const message = document.getElementById("guessMessage");
|
||
|
||
if (input.value.trim() === "" || guess < 1 || guess > 20 || !Number.isInteger(guess)) {
|
||
message.textContent = "Bitte eine ganze Zahl zwischen 1 und 20 eingeben.";
|
||
message.className = "message error"; return;
|
||
}
|
||
if (gameWon) { message.textContent = "Starte zuerst ein neues Spiel."; return; }
|
||
attempts++;
|
||
if (guess === secretNumber) {
|
||
message.textContent = "Richtig! Du hast die Zahl erraten.";
|
||
message.className = "message success"; gameWon = true;
|
||
} else if (guess < secretNumber) {
|
||
message.textContent = "Die gesuchte Zahl ist größer.";
|
||
message.className = "message";
|
||
} else {
|
||
message.textContent = "Die gesuchte Zahl ist kleiner.";
|
||
message.className = "message";
|
||
}
|
||
document.getElementById("guessAttempts").textContent = "Versuche: " + attempts;
|
||
});
|
||
document.getElementById("newGuessButton").addEventListener("click", () => {
|
||
secretNumber = Math.floor(Math.random() * 20) + 1;
|
||
attempts = 0; gameWon = false;
|
||
document.getElementById("guessInput").value = "";
|
||
document.getElementById("guessMessage").textContent = "";
|
||
document.getElementById("guessAttempts").textContent = "Versuche: 0";
|
||
});
|
||
|
||
// ARRAY-METHODEN
|
||
const numbers = [23, 4, 15, 8, 42, 2, 16];
|
||
document.getElementById("runArrayButton").addEventListener("click", () => {
|
||
const operation = document.getElementById("arrayOperation").value;
|
||
let result;
|
||
switch (operation) {
|
||
case "show": result = numbers; break;
|
||
case "filter": result = numbers.filter(number => number > 10); break;
|
||
case "map": result = numbers.map(number => number * 2); break;
|
||
case "sort": result = [...numbers].sort((a, b) => a - b); break;
|
||
case "sum": result = numbers.reduce((total, number) => total + number, 0); break;
|
||
case "find": result = numbers.find(number => number > 10); break;
|
||
case "max": result = Math.max(...numbers); break;
|
||
}
|
||
document.getElementById("arrayOutput").textContent = JSON.stringify(result, null, 2);
|
||
});
|
||
|
||
// SORTIEREN UND MISCHEN
|
||
let sortableNumbers = [23, 4, 15, 8, 42, 2];
|
||
function showSortedNumbers() {
|
||
document.getElementById("sortOutput").textContent = sortableNumbers.join(", ");
|
||
}
|
||
document.getElementById("sortAscending").addEventListener("click", () => {
|
||
sortableNumbers.sort((a, b) => a - b); showSortedNumbers();
|
||
});
|
||
document.getElementById("sortDescending").addEventListener("click", () => {
|
||
sortableNumbers.sort((a, b) => b - a); showSortedNumbers();
|
||
});
|
||
document.getElementById("shuffleNumbers").addEventListener("click", () => {
|
||
sortableNumbers.sort(() => Math.random() - .5); showSortedNumbers();
|
||
});
|
||
|
||
// OBJEKTE
|
||
const person = { name: "Anna", alter: 17, beruf: "Schülerin", lieblingsfach: "Informatik" };
|
||
document.getElementById("showObjectButton").addEventListener("click", () => {
|
||
document.getElementById("objectOutput").textContent =
|
||
"Name: " + person.name + "\n" +
|
||
"Alter: " + person.alter + "\n" +
|
||
"Beruf: " + person.beruf + "\n" +
|
||
"Lieblingsfach: " + person.lieblingsfach;
|
||
});
|
||
|
||
// TABELLE MIT FILTER
|
||
const tablePeople = [
|
||
{ name: "Anna", alter: 17, beruf: "Schülerin" },
|
||
{ name: "Max", alter: 20, beruf: "Student" },
|
||
{ name: "Lisa", alter: 25, beruf: "Entwicklerin" },
|
||
{ name: "Tom", alter: 30, beruf: "Designer" },
|
||
{ name: "Sarah", alter: 22, beruf: "Studentin" }
|
||
];
|
||
function renderTable(searchTerm = "") {
|
||
const tbody = document.getElementById("tableBody");
|
||
tbody.replaceChildren();
|
||
const filteredPeople = tablePeople.filter(person =>
|
||
(person.name + " " + person.beruf).toLowerCase().includes(searchTerm.toLowerCase())
|
||
);
|
||
filteredPeople.forEach(person => {
|
||
const row = document.createElement("tr");
|
||
[person.name, person.alter, person.beruf].forEach(value => {
|
||
const cell = document.createElement("td");
|
||
cell.textContent = value; row.appendChild(cell);
|
||
});
|
||
tbody.appendChild(row);
|
||
});
|
||
document.getElementById("tableResultCount").textContent = filteredPeople.length + " Personen gefunden.";
|
||
}
|
||
document.getElementById("tableSearch").addEventListener("input", function () { renderTable(this.value.trim()) });
|
||
renderTable();
|
||
|
||
// AKKORDEON
|
||
document.querySelectorAll(".accordion-button").forEach(button => {
|
||
button.addEventListener("click", () => {
|
||
document.getElementById(button.dataset.accordion).classList.toggle("open");
|
||
});
|
||
});
|
||
|
||
// NOTIZBLOCK
|
||
const noteInput = document.getElementById("noteInput");
|
||
const noteMessage = document.getElementById("noteMessage");
|
||
document.getElementById("saveNoteButton").addEventListener("click", () => {
|
||
localStorage.setItem("learningNote", noteInput.value);
|
||
noteMessage.textContent = "Notiz gespeichert.";
|
||
noteMessage.className = "message success";
|
||
});
|
||
document.getElementById("loadNoteButton").addEventListener("click", () => {
|
||
const savedNote = localStorage.getItem("learningNote");
|
||
if (savedNote === null) {
|
||
noteMessage.textContent = "Keine gespeicherte Notiz vorhanden.";
|
||
noteMessage.className = "message error";
|
||
} else {
|
||
noteInput.value = savedNote;
|
||
noteMessage.textContent = "Notiz geladen.";
|
||
noteMessage.className = "message success";
|
||
}
|
||
});
|
||
document.getElementById("deleteNoteButton").addEventListener("click", () => {
|
||
localStorage.removeItem("learningNote");
|
||
noteInput.value = "";
|
||
noteMessage.textContent = "Notiz gelöscht.";
|
||
noteMessage.className = "message success";
|
||
});
|
||
|
||
// DATUM UND UHRZEIT
|
||
document.getElementById("showDateButton").addEventListener("click", () => {
|
||
const now = new Date();
|
||
document.getElementById("dateOutput").textContent =
|
||
"Datum: " + now.toLocaleDateString("de-AT") + "\nUhrzeit: " + now.toLocaleTimeString("de-AT");
|
||
});
|
||
|
||
// STRING-METHODEN
|
||
document.getElementById("processStringButton").addEventListener("click", () => {
|
||
const original = document.getElementById("stringInput").value;
|
||
document.getElementById("stringOutput").textContent =
|
||
"Original: " + original + "\n" +
|
||
"Großbuchstaben: " + original.toUpperCase() + "\n" +
|
||
"Kleinbuchstaben: " + original.toLowerCase() + "\n" +
|
||
"Zeichenanzahl: " + original.length + "\n" +
|
||
"Ohne Leerzeichen außen: " + original.trim() + "\n" +
|
||
"Enthält 'a': " + original.toLowerCase().includes("a");
|
||
});
|
||
|
||
// ANIMATION
|
||
document.getElementById("animateButton").addEventListener("click", () => {
|
||
const box = document.getElementById("animationBox");
|
||
box.classList.remove("animate");
|
||
void box.offsetWidth;
|
||
box.classList.add("animate");
|
||
});
|
||
|
||
// CHECKLISTE UND FORTSCHRITT
|
||
const studyChecks = document.querySelectorAll(".studyCheck");
|
||
function updateProgress() {
|
||
const checks = Array.from(studyChecks);
|
||
const completed = checks.filter(check => check.checked).length;
|
||
const total = checks.length;
|
||
const percentage = total === 0 ? 0 : completed / total * 100;
|
||
document.getElementById("progressText").textContent = completed + " von " + total + " Themen erledigt";
|
||
document.getElementById("progressBar").style.width = percentage + "%";
|
||
}
|
||
studyChecks.forEach(checkbox => checkbox.addEventListener("change", updateProgress));
|
||
|
||
// CODE-REFERENZ
|
||
const codeExamples = {
|
||
variable: `const name = "Anna";
|
||
let alter = 17;
|
||
alter = 18;
|
||
console.log(name);
|
||
console.log(alter);`,
|
||
|
||
condition: `const alter = 18;
|
||
if (alter >= 18) {
|
||
console.log("Volljährig");
|
||
} else {
|
||
console.log("Nicht volljährig");
|
||
}`,
|
||
|
||
function: `function addiere(a, b) {
|
||
return a + b;
|
||
}
|
||
const ergebnis = addiere(4, 6);
|
||
console.log(ergebnis);`,
|
||
|
||
event: `const button = document.querySelector("#button");
|
||
button.addEventListener("click", function () {
|
||
console.log("Angeklickt!");
|
||
});`,
|
||
|
||
loop: `for (let i = 0; i < 5; i++) {
|
||
console.log(i);
|
||
}`,
|
||
|
||
array: `const namen = ["Anna", "Max", "Lisa"];
|
||
namen.forEach(function (name) {
|
||
console.log(name);
|
||
});`,
|
||
|
||
filter: `const zahlen = [2, 8, 12, 17];
|
||
const ergebnis = zahlen.filter(zahl => zahl > 10);
|
||
console.log(ergebnis);`,
|
||
|
||
map: `const zahlen = [1, 2, 3];
|
||
const verdoppelt = zahlen.map(zahl => zahl * 2);
|
||
console.log(verdoppelt);`,
|
||
|
||
object: `const person = {
|
||
name: "Anna",
|
||
alter: 17
|
||
};
|
||
console.log(person.name);`,
|
||
|
||
dom: `const absatz = document.createElement("p");
|
||
absatz.textContent = "Hallo Welt!";
|
||
document.body.appendChild(absatz);`,
|
||
|
||
try: `try {
|
||
const data = JSON.parse('{"name":"Anna"}');
|
||
console.log(data.name);
|
||
} catch (error) {
|
||
console.log("Fehler aufgetreten.");
|
||
}`
|
||
};
|
||
|
||
const codeSelect = document.getElementById("codeSelect");
|
||
const codeDisplay = document.getElementById("codeDisplay");
|
||
function displayCode() {
|
||
codeDisplay.textContent = codeExamples[codeSelect.value];
|
||
}
|
||
codeSelect.addEventListener("change", displayCode);
|
||
document.getElementById("copyCodeButton").addEventListener("click", async () => {
|
||
const copyMessage = document.getElementById("copyMessage");
|
||
try {
|
||
await navigator.clipboard.writeText(codeDisplay.textContent);
|
||
copyMessage.textContent = "Code kopiert!";
|
||
copyMessage.className = "message success";
|
||
} catch (error) {
|
||
copyMessage.textContent = "Kopieren nicht möglich. Markiere den Code manuell.";
|
||
copyMessage.className = "message error";
|
||
}
|
||
});
|
||
|
||
// MODAL
|
||
const modal = document.getElementById("infoModal");
|
||
document.getElementById("openModalButton").addEventListener("click", () => modal.classList.add("open"));
|
||
document.getElementById("closeModalButton").addEventListener("click", () => modal.classList.remove("open"));
|
||
modal.addEventListener("click", event => {
|
||
if (event.target === modal) modal.classList.remove("open");
|
||
});
|
||
document.addEventListener("keydown", event => {
|
||
if (event.key === "Escape") modal.classList.remove("open");
|
||
});
|
||
|
||
// STARTINITIALISIERUNG
|
||
displayCode();
|
||
updateTaskCounter();
|
||
updateProgress();
|
||
console.log("Die Lernplattform wurde erfolgreich geladen.");
|
||
|
||
|
||
|
||
|
||
// ==================================================
|
||
// ZURÜCK-NACH-OBEN-FUNKTION
|
||
// ==================================================
|
||
|
||
const backToTop = document.getElementById("backToTop");
|
||
|
||
// Beim Scrollen prüfen, ob der Pfeil angezeigt werden soll.
|
||
window.addEventListener("scroll", function () {
|
||
|
||
// Ab 300 Pixel Scrollstrecke wird der Pfeil sichtbar.
|
||
if (window.scrollY > 300) {
|
||
backToTop.classList.add("visible");
|
||
} else {
|
||
backToTop.classList.remove("visible");
|
||
}
|
||
|
||
});
|
||
|
||
// Beim Klick sanft nach oben scrollen.
|
||
backToTop.addEventListener("click", function () {
|
||
|
||
window.scrollTo({
|
||
top: 0,
|
||
behavior: "smooth"
|
||
});
|
||
|
||
});
|
||
|
||
|
||
|
||
|
||
|
||
</script>
|
||
|
||
<footer>
|
||
<div class="container">JavaScript Lernplattform – HTML, CSS und JavaScript in einer Datei</div>
|
||
</footer>
|
||
</body>
|
||
|
||
</html> |