So I want to have a lottie animation start when I successfully submit a form however the lottie automatically plays when I try the “Scroll into view lottie playback.” So my next solution to this is to make it so when the button presses submit, the lottie will start to animate. OR I can press the submit button and then the lottie will become visible and then start to play. Any way to code that in custom code?
// Select all elements with the class .form__success__icon
const formSuccessIcons = document.querySelectorAll('.form__success__icon');
// Check if any .form__success__icon elements exist on the page
if (formSuccessIcons.length > 0) {
// Loop through each element in the formSuccessIcons NodeList
formSuccessIcons.forEach(formSuccessIcon => {
// Create a new Intersection Observer for each .form__success__icon element
const observer = new IntersectionObserver((entries, observer) => {
// Iterate over each entry (each observed element)
entries.forEach(entry => {
// Check if the current entry (element) is intersecting with the viewport
if (entry.isIntersecting) {
// Trigger a click event on the intersecting element
entry.target.click();
// Unobserve the current element after the click to prevent it from triggering again
observer.unobserve(entry.target);
}
});
});
// Start observing the current .form__success__icon element
observer.observe(formSuccessIcon);
});
}