Skip to content
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

Improve the README.md #8

Open
vaibhav111tandon opened this issue Oct 11, 2019 · 5 comments
Open

Improve the README.md #8

vaibhav111tandon opened this issue Oct 11, 2019 · 5 comments
Labels

Comments

@vaibhav111tandon
Copy link
Owner

Add the usage of classes through JavaScript and jQuery

@akhilkh2000
Copy link

Can you explain this issue in detail?

@vaibhav111tandon
Copy link
Owner Author

You can give a short jquery or javascript snippet to use these animation classes. A short demo type...

@gurman8571
Copy link

still open???

@chimok
Copy link

chimok commented May 27, 2024

Hello @vaibhav111tandon,

i could add my snippet from #34 which is a frequently use for such animations

@chimok
Copy link

chimok commented Jun 25, 2024

@vaibhav111tandon This is my javascript how i add css classes when the element is in viewport

/**
 * Add a css class when the element appears in viewport
 *
 * @param {IntersectionObserverEntry[]} entries
 */
function func2(entries) {
    entries.forEach(entry => {
        const elem = entry.target;
        if (entry.isIntersecting) {
            elem.classList.add('in-viewport');
            observer.unobserve(elem);
        }
    })
}

const observer = new IntersectionObserver(func2, {
    root: null,
    rootMargin: '0px',
    threshold: .5
});

/**
 * Set or remove a css class when the element is in viewport
 *
 * @param {string} selector
 */
export function inViewport(selector = '.if-viewport') {
    document.querySelectorAll(selector).forEach(elem => {
        observer.observe(elem);
    });
}

The HTML looks like:

<div class="if-viewport vov fade-in-up">
  This is some content with a fade-in-up animation when if appears in viewport
</div>

The javascript adds the in-viewport css class if element is in viewport.

The issue I have, the initial state before it is visible in the viewport should be opacity:0 and placed with a bottom offset. Are there CSS classes for it already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants