Skip to content

Commit

Permalink
updated theme toggle with all new themes
Browse files Browse the repository at this point in the history
here are two themes for your website dark and light .
  • Loading branch information
STDYGIT committed Oct 3, 2024
1 parent 23194a3 commit 70b84da
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5503
}
Binary file added Assets/moon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

<body>
<header class="header">
<h1>OpenTekHub Blockchain Repository</h1>
<nav>
<h1>OpenTekHub Blockchain Repository</h1>
<div class="theme-switch" id="theme-switch"></div>
</nav>
</header>

<div class="central">
<p class="tagline">Explore the Blockchain implementation and predict the latest cryptocurrency prices.</p>

<section id="crypto-price-predictor">
<h2>Crypto Price Predictor</h2>
<div id="crypto-form">
Expand Down
40 changes: 40 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
// Dark Mode Toggle Functionality
const themeSwitch = document.getElementById('theme-switch'); // Ensure this matches your HTML button's ID
const body = document.body;
const header = document.querySelector('header');
const footer = document.querySelector('footer');

// Function to enable dark mode
function enableDarkMode() {
body.classList.add('dark-mode');
header.classList.add('dark-mode');
themeSwitch.classList.add('dark-theme'); // Update the switch appearance
footer.classList.add('dark-mode');
}

// Function to disable dark mode
function disableDarkMode() {
body.classList.remove('dark-mode');
header.classList.remove('dark-mode');
themeSwitch.classList.remove('dark-theme'); // Update the switch appearance
footer.classList.remove('dark-mode');
}

// Event listener for dark mode toggle button
themeSwitch.addEventListener('click', () => {
if (body.classList.contains('dark-mode')) {
disableDarkMode(); // Switch to light mode
localStorage.removeItem('dark-mode'); // Remove from local storage
} else {
enableDarkMode(); // Switch to dark mode
localStorage.setItem('dark-mode', 'enabled'); // Save in local storage
}
});

// Optional: Check the initial mode on page load and apply the correct theme based on local storage
if (localStorage.getItem('dark-mode') === 'enabled') {
enableDarkMode();
} else {
disableDarkMode(); // Default to light mode on load if localStorage is empty
}
// A map of symbols to their corresponding API names
const cryptoMap = {
// Major cryptocurrencies
Expand Down Expand Up @@ -158,3 +197,4 @@ document.getElementById('predict-btn').addEventListener('click', function() {
document.getElementById("price").innerText = "Please enter a valid cryptocurrency symbol.";
}
});

53 changes: 52 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ h1, h2, h3 {

.header {
text-align: center;
background-color: #2E073F;
background: linear-gradient(135deg, rgb(36, 11, 54), rgb(195, 20, 50));
color: #EBD3F8;
padding: 1.2rem;
font-family: "Mate SC", serif;
Expand Down Expand Up @@ -251,4 +251,55 @@ h1, h2, h3 {
.bot-text{
font-size: 1rem;
margin-block: 0px;
}


/* Here are the styles for the theme toggel */
/* Theme switcher */
.theme-switch {
display: inline-block;
width: 60px;
height: 30px;
border-radius: 30px;
background: linear-gradient(116deg, #ffffff, #a00101);
position: relative;
cursor: pointer;
transition: background 0.3s ease-in-out;
vertical-align: middle;
}

.theme-switch::before {
content: '';
position: absolute;
top: 3px;
left: 3px; /* Initial position for light mode */
width: 24px;
height: 24px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
transition: left 0.3s ease-in-out, background-image 0.3s ease-in-out;
background-image: url('Assets/moon.png'); /* Icon for light mode */
}

.theme-switch.dark-theme {
background: linear-gradient(92deg, #ff0000, #ffffff); /* Background for dark mode */
}

.theme-switch.dark-theme::before {
left: 33px; /* Move the toggle to the right for dark mode */
background-image: url('Assets/sun.png'); /* Icon for dark mode */
}

/* Other dark mode styles */
.header.dark-mode {
background: linear-gradient(303deg, #000000, #500210);
}

body.dark-mode{
background: linear-gradient(303deg, #000000, #500210);
color: #ffecec;
}
p.tagline.dark-mode{
color: #ffffff;
}

0 comments on commit 70b84da

Please sign in to comment.