mirror of
https://github.com/micku7zu/vanilla-tilt.js
synced 2024-06-27 17:40:02 +02:00
Don't instantiate a new class if is already there
This commit is contained in:
parent
5830d047d3
commit
4ed021d6b0
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue