Add loadParticles() and setParticles()
This commit is contained in:
parent
eaf46e9915
commit
627fa59d38
|
@ -1,12 +1,13 @@
|
||||||
let toggleTheme = (theme) => {
|
let toggleTheme = (theme) => {
|
||||||
if (theme == "dark") {
|
if (theme == "dark") {
|
||||||
setTheme("light");
|
setTheme("light");
|
||||||
|
loadParticles("light")
|
||||||
} else {
|
} else {
|
||||||
setTheme("dark");
|
setTheme("dark");
|
||||||
|
loadParticles("dark")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let setTheme = (theme) => {
|
let setTheme = (theme) => {
|
||||||
transTheme();
|
transTheme();
|
||||||
if (theme) {
|
if (theme) {
|
||||||
|
@ -46,3 +47,32 @@ let initTheme = (theme) => {
|
||||||
|
|
||||||
|
|
||||||
initTheme(localStorage.getItem("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