Don't instantiate a new class if is already there

This commit is contained in:
micku7zu 2017-01-28 21:58:38 +02:00
parent 5830d047d3
commit 4ed021d6b0
2 changed files with 5 additions and 4 deletions

View file

@ -3027,13 +3027,10 @@ element.addEventListener("tiltChange", function(event){ console.log(event.detail
var tiltOutput = document.querySelector(".js-tilt-output");
var output = document.querySelector(".js-output");
VanillaTilt.init(elements);
VanillaTilt.init(tiltOutput);
tiltOutput.addEventListener("tiltChange", function (event) {
console.log("TEST");
var li = document.createElement("li");
li.textContent = JSON.stringify(event.detail);
output.insertBefore(li, output.firstChild);

View file

@ -47,6 +47,8 @@
destroy() {
this.removeEventListeners();
this.element.vanillaTilt = null;
delete this.element.vanillaTilt;
this.element = null;
}
@ -178,7 +180,9 @@
}
elements.forEach((element) => {
element.vanillaTilt = new VanillaTilt(element, settings);
if (!("vanillaTilt" in element)) {
element.vanillaTilt = new VanillaTilt(element, settings);
}
});
}
}