-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
On scroll delay? #51
Comments
I think the best solution would be use this with IntersectionObserver. Once the observer lets you know the content is visible you can call |
I assembled something like this. Perhaps it helps someone else. import { annotate } from 'rough-notation';
const observer = new IntersectionObserver(handleIntersection, { threshold: [1] });
let annotations;
document.addEventListener('DOMContentLoaded', function () {
annotations = Array.from(document.querySelectorAll('*[data-annotate]'))
.map((element, i) => {
const id = i.toString();
const annotation = annotate(element, {
type: 'circle',
color: '#1755d1',
padding: 20,
animationDuration: 1600,
});
element.dataset.annotateId = id;
observer.observe(element);
return { id, annotation };
});
});
function handleIntersection(entries, observer) {
entries
.filter((entry) => entry.isIntersecting)
.forEach((entry) => {
const element = entry.target;
const annotation = annotations
.filter(({ id }) => id === element.dataset.annotateId)[0].annotation;
annotation.show();
});
} The elements are found based on having the There's global variable and all in all it's not the most beautiful JS I've ever written, but it's vanilla solution to the problem. If you want to customize when exactly the animation starts, see the Intersection Observer API docs at MDN. The key part is the |
@pshihn Perhaps this could make it to docs in some form? I guess this might be a frequent way of using the annotations. |
Hoping this might help someone!
|
I'm trying to implement this, I am working on a site that uses fullpage.js and I want the animation to start when the user has scrolled into a sections slide. This is the code I have in place, I can't get your code to work with the working example I have: import { const n2 = document.querySelector("strong"); const a2 = annotate(n2, { type: "circle", color: "red", padding: 10, animationDuration: 1600 }); const ag = annotationGroup([a2]); |
Great library for starters but is there a way to delay the annotation until you've scrolled to a section on the page? I'm using the code below ATM. Thanks
`const annotate = RoughNotation.annotate;
const annotationGroup = RoughNotation.annotationGroup;
const g1 = annotate(document.querySelector('.highlight'), {
type: 'highlight',
color: '#FAE633',
multiline: true,
animationDuration: 1500,
animationDelay: 3000,
iterations: 1
});
const ag = annotationGroup([g1]);
ag.show();
`
The text was updated successfully, but these errors were encountered: