Skip to content

Commit

Permalink
TP theme clair/theme sombre
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeeppy committed May 1, 2023
1 parent 09521e7 commit a49fdf6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
32 changes: 32 additions & 0 deletions session31/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 mt-5 text-center">
<h1>Bienvenue</h1>
<p class="mt-3">Ce site est en construction. Il ne gère que le choix du thème pour le moment.</p>
</div>
</div>

<div class="row justify-content-center">
<div class="col-md-8 mt-5 text-center">
<button id="mode">
<i class="fas fa-moon"></i>
<span>Thème sombre</span>
</button>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions session31/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
let button = document.querySelector("#mode");
let span = button.querySelector('span');

if (localStorage.getItem("theme") && localStorage.getItem("theme") === 'sombre')
{
modeSombre();
}

button.addEventListener('click', () => {
if (document.body.classList.contains('dark'))
{
document.body.classList = '';
span.textContent = "Thème sombre";
localStorage.setItem("theme", "clair");
} else {
modeSombre();
}
})

function modeSombre() {
document.body.classList.add('dark');
span.textContent = "Thème clair";
localStorage.setItem("theme", "sombre");
}
25 changes: 25 additions & 0 deletions session31/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
html, body {
font-family: arial;
min-width: 300px;
}

button {
border: 1px;
border-radius: 15px;
padding: 15px;
cursor: pointer;
}

* {
outline: 0;
}

.dark {
background-color: #112F41;
color: #ffffff;
}

.dark button {
background: #144098;
color: #fff;
}

0 comments on commit a49fdf6

Please sign in to comment.