Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the dynamic background #4374

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
transition: background-color 4s ease;
overflow-x: hidden;}
#about {
color: white;
Expand Down
27 changes: 27 additions & 0 deletions assets/js/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const randomColor = () => {
const hex = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += hex[Math.floor(Math.random() * 16)];
}
return color;
};

let id;

const startChanging = () => {
if (!id) { // better practice
id = setInterval(change, 2500); // Set interval to 2000 milliseconds (2 seconds)
}
function change() {
document.body.style.backgroundColor = randomColor();
}
};

const stopChanging = () => {
clearInterval(id);
id = null; // flushes out the value after stop and hence no overriding
};

// Start changing colors when the page loads
window.onload = startChanging;
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ <h2 id="total-contributors" style="text-align: center; font-family: 'Agency FB',
<script src="./assets/js/contributors.js"></script>
<script src="./assets/js/cursor_transition.js"></script>
<script src="./assets/js/contributors.js"></script>

<script src="./assets/js/background.js"></script>



Expand Down
Loading