Add loadParticles() and setParticles()
This commit is contained in:
parent
eaf46e9915
commit
627fa59d38
|
@ -1,12 +1,13 @@
|
|||
let toggleTheme = (theme) => {
|
||||
if (theme == "dark") {
|
||||
setTheme("light");
|
||||
loadParticles("light")
|
||||
} else {
|
||||
setTheme("dark");
|
||||
loadParticles("dark")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let setTheme = (theme) => {
|
||||
transTheme();
|
||||
if (theme) {
|
||||
|
@ -46,3 +47,32 @@ let initTheme = (theme) => {
|
|||
|
||||
|
||||
initTheme(localStorage.getItem("theme"));
|
||||
|
||||
let loadParticles = (theme) => {
|
||||
var matches = document.baseURI.match(/\//g);
|
||||
var count = matches ? matches.length : 0;
|
||||
if (count != 3)
|
||||
return;
|
||||
|
||||
if (!theme)
|
||||
setParticles(localStorage.getItem("theme"))
|
||||
else
|
||||
setParticles(theme)
|
||||
}
|
||||
|
||||
let setParticles = (theme) => {
|
||||
if (theme == "dark") {
|
||||
try {
|
||||
particlesJS.load('particles-js', 'assets/json/particles-dark.json');
|
||||
} catch(e) {
|
||||
console.log('ERROR: particles-js is not loaded.')
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
particlesJS.load('particles-js', 'assets/json/particles-light.json');
|
||||
} catch(e) {
|
||||
console.log('ERROR: particles-js is not loaded.')
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue