generated from alshedivat/al-folio
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tonideleo/SimpleParallaxJS
Simple Parallax JS - Fixed Particle JS integration with dark/light/system mode
- Loading branch information
Showing
8 changed files
with
836 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
/* particlesJS.load(@dom-id, @path-json, @callback (optional)); */ | ||
particlesJS.load('particles-js', '/assets/json/particles.json', function() { | ||
console.log('callback - particles.js config loaded'); | ||
document.addEventListener("DOMContentLoaded", function () { | ||
// Function to determine the user's system theme preference | ||
const getSystemTheme = () => { | ||
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||
return "dark"; | ||
} | ||
return "light"; | ||
}; | ||
|
||
// Load and modify particles configuration based on the system theme | ||
particlesJS.load('particles-js', '/assets/json/particles.json', function() { | ||
console.log('callback - particles.js config loaded'); | ||
|
||
// Modify particle colors based on the theme | ||
const theme = getSystemTheme(); | ||
const particles = pJSDom[0].pJS.particles; | ||
|
||
if (theme === "dark") { | ||
particles.color.value = '#ffffff'; | ||
particles.line_linked.color = '#ffffff'; | ||
} else { | ||
particles.color.value = '#000000'; | ||
particles.line_linked.color = '#000000'; | ||
} | ||
|
||
// Refresh particles.js settings | ||
pJSDom[0].pJS.fn.particlesRefresh(); | ||
}); | ||
}); |
Oops, something went wrong.