Skip to content

Commit

Permalink
Merge pull request #66 from LottieFiles/fix/ownerdocument
Browse files Browse the repository at this point in the history
fix: fixed container null issue on wordpress
  • Loading branch information
samuelOsborne authored Mar 7, 2022
2 parents c435d0e + fa0e5e7 commit 31863e0
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,15 @@ export class LottieInteractivity {
this.playCounter = 0;
this.stateHandler = new Map();
this.transitionHandler = new Map();

//globals
this.window = this.container.ownerDocument.defaultView;
}

getContainerVisibility() {
// Get the bounding box for the lottie player or container
const { top, height } = this.container.getBoundingClientRect();

// Calculate current view percentage
const current = this.window.innerHeight - top;
const max = this.window.innerHeight + height;
const current = window.innerHeight - top;
const max = window.innerHeight + height;
return current / max;
}

Expand All @@ -84,7 +81,7 @@ export class LottieInteractivity {

initScrollMode() {
this.player.stop();
this.window.addEventListener('scroll', this.#scrollHandler, true);
window.addEventListener('scroll', this.#scrollHandler, true);
}

initCursorMode() {
Expand Down Expand Up @@ -229,7 +226,7 @@ export class LottieInteractivity {

stop() {
if (this.mode === 'scroll') {
this.window.removeEventListener('scroll', this.#scrollHandler, true);
window.removeEventListener('scroll', this.#scrollHandler, true);
}

if (this.mode === 'cursor') {
Expand Down Expand Up @@ -680,22 +677,22 @@ export class LottieInteractivity {
throw new Error(`${ERROR_PREFIX} Specified player is invalid.`, this.enteredPlayer);
}
} else {
if (this.window.lottie) {
if (window.lottie) {
this.stop();
this.player.destroy();
// Removes svg animation contained inside
this.container.innerHTML = "";

if (typeof path === 'object' && path.constructor.name === 'AnimationItem') {
this.player = this.window.lottie.loadAnimation({
this.player = window.lottie.loadAnimation({
loop: false,
autoplay: false,
animationData: path.animationData,
container: this.container
});
}
else {
this.player = this.window.lottie.loadAnimation({
this.player = window.lottie.loadAnimation({
loop: false,
autoplay: false,
path,
Expand Down

0 comments on commit 31863e0

Please sign in to comment.