// set array of Vanta effects
var bgEffects = {
"0": VANTA.BIRDS,
"1": VANTA.CLOUDS,
"2": VANTA.CLOUDS2,
"3": VANTA.FOG,
"4": VANTA.WAVES,
"5": VANTA.DOTS,
"6": VANTA.HALO
}
// DOM event listener for dropdown selector
document.getElementById("effect").addEventListener("change", () => runFunction());
// DOM event listener for disable button
// Bootstrap checkboxes require using jQuery to select
$("#button1").change(function() {
disableFunction();
});
// DOM event listener for hide button
document.getElementById("button2").addEventListener("click", () => hideFunction());
// DOM event listener for remove button
document.getElementById("button3").addEventListener("click", () => removeFunction());
// Function to initialize the Vanta background
function runFunction() {
const effectID = document.getElementById("effect").value;
bgEffects[effectID]({
//el: document.getElementById("vantajs-bg"),
el: '#vantajs-bg',
mouseControls: true,
touchControls: true,
gyroControls: true,
minHeight: 200.00,
minWidth: 200.00,
scale: 1.00,
scaleMobile: 1.00
});
}
runFunction(); // fire function on page load
// function to destroy the Vanta effect
function disableFunction() {
const effectID = document.getElementById("effect").value;
bgEffects[effectID]('#vantajs-bg').destroy()
//VANTA.HALO('#vantajs-bg').destroy() // This doesn't work either
console.log(`Vanta effect destroyed`)
}
// function to hide the Vanta background
// This is undesirable, since it hides the entire contents of the div
function hideFunction() {
var x = document.getElementById("vantajs-bg");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
// function to remove the Vanta background
// This is undesirable, since it hides the entire contents of the div
function removeFunction() {
var y = document.getElementById("vantajs-bg");
y.remove();
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.