Skip to content

[FEATURE] Add option for intersection observer rootMargin #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/josh.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Josh {
this.initDom = document.querySelectorAll("." + this.initClass);
// Animation library class. Default class is 'animate__animated'
this.animClass = options.animClass || "animate__animated";
// Intersection observer root margin (e.g. "0px 0px -20% 0px" animates the element once it reaches 20% from the bottom of the viewport)
this.margin = options.margin || "0px";
// Number 0 to 1, 0.2 means if the element come to 20% percent of view it will animate. Default value is 0.2
this.offset = options.offset || 0.2;
// Boolean value to animate in mobile or not. Default value is true
Expand Down Expand Up @@ -87,7 +89,7 @@ class Josh {
this.intersectionObserverCallback.bind(this),
{
root: null,
rootMargin: "0px",
rootMargin: this.margin,
threshold: this.offset,
}
);
Expand Down