Skip to content

Commit

Permalink
Add theme persistence and responsive styles
Browse files Browse the repository at this point in the history
Implemented theme persistence using session storage for theme switching. Updated CSS for better alignment and smoother transitions on different screen sizes. Integrated Bootstrap, jQuery libraries, and cleaned redundant inline styles in index.html.
  • Loading branch information
MatejMa2ur committed Oct 10, 2024
1 parent d27ed97 commit 040d274
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .idea/MatejMa2ur.github.io.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 42 additions & 50 deletions index.html

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion js/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
document.getElementById('theme-switcher').addEventListener('click', function () {
// Function to toggle the theme and save it to session storage
const toggleTheme = () => {
const body = document.body;
const currentTheme = body.getAttribute('data-bs-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
body.setAttribute('data-bs-theme', newTheme);
sessionStorage.setItem('theme', newTheme);
};

// Add event listener to the theme switcher button
document.getElementById('theme-switcher').addEventListener('click', toggleTheme);

// Check session storage for saved theme on page load
window.addEventListener('DOMContentLoaded', () => {
const savedTheme = sessionStorage.getItem('theme') || 'light';
document.body.setAttribute('data-bs-theme', savedTheme);
});
60 changes: 60 additions & 0 deletions style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,64 @@ body[data-bs-theme="dark"] {
--bs-body-color: var(--light-300);
--bs-emphasis-color: var(--light-200);
--bs-secondary-color: var(--yellow);
}

.screen{
position: relative;
height: 100vh;
width: 100%;
}
.links{
margin-top: 1em;
margin-right: 0.5em;
}

.links a{
width: 100%;
padding: 10px 2em;
margin: 0.2em;
border-radius: 5px;
text-decoration: none;
color: var(--light-300);
background-color: var(--bs-secondary-color);
}

/* Index.html */
.circle-color, .person-color {
transition: fill 0.4s ease-out;
}
body{
transition: background-color 0.4s ease-out;
}
svg#theme-switcher {
cursor: pointer;
}
svg#theme-switcher {
width: 612px;
height: 600px;
}

.tilt-text h2 {
transition: transform 0.3s ease-out; /* Add animation for smooth transition */
}
/* Media query for phone screens */
@media (max-width: 576px) {
.tilt-text {
padding-left: 0.8em;
padding-top: 6.5em;
}
.tilt-text h2 {
transform: rotate(-45deg);
margin-left: -0.5em;
}
svg#theme-switcher {
width: 400px;
height: 392px;
}
.hidden-right {
position: absolute;
right: -20%; /* Move element far enough to the right to hide it completely */
bottom: -5%;
width: 100%;
}
}

0 comments on commit 040d274

Please sign in to comment.