R
R
Roman Frell2020-12-25 00:10:02
css
Roman Frell, 2020-12-25 00:10:02

Make text animation when scrolling through the page?

I really liked the animation of the text when scrolling the page ( surl.li/iliw ) - who can tell how this can be implemented.
It would also be interesting to know what effect on the video when scrolling.?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Bogdan Shevchenko, 2020-12-25
@Glecko

const animItems = document.querySelectorAll(`._anim-items`)
if (animItems.length > 0) {
    window.addEventListener(`scroll`, animOnScroll)

    function animOnScroll() {
        for (let index = 0; index < animItems.length; index++) {
            const animItem = animItems[index]
            const animItemHeight = animItem.offsetHeight
            const animItemOffSet = offset(animItem).top
            const animStart = 4
            let animItemPoint = window.innerHeight - animItemHeight / animStart
            if (animItemHeight > window.innerHeight) {
                animItemPoint = window.innerHeight - window.innerHeight / animStart
            }
            if ((pageYOffset > animItemOffSet - animItemPoint) && pageYOffset < (animItemOffSet + animItemHeight)) {
                animItem.classList.add(`_active`)
            } else {
                if (!(animItem.classList.contains(`_anim-no-hide`))) {
                    animItem.classList.remove(`_active`)
                }
            }
        }
    }

    function offset(el) {
        const rect = el.getBoundingClientRect()
        let scrollLeft = window.pageXOffset || document.documentElement.scrollLeft
        let scrollTop = window.pageYOffset || document.documentElement.scrollTop
        return {top: rect.top + scrollTop, left: rect.left + scrollLeft}
    }

    setTimeout(() => {
        animOnScroll()
    }, 300)
}

to trigger the animation, add the _anim-items class ( + _anim-no-hide if you don't need animation when scrolling again), and add the animation itself to css
.header {
  transform: translate(0, -80%);
  opacity: 0.5;
  transition: all 1s ease 0s;
}
.header._active {
  transform: translate(0, 0);
  opacity: 1;
}

An example can be seen here: https://github.com/GleckoS/Studio-Urody-An-In

E
Evgeny Golubev, 2020-12-25
@bestowhope

1 in 1 I will not prompt. Obviously made by hand.
Smoke it . For text, that's it. And bg I think you'll get a taste of how to glitch
Example | Source
Most suitable A6

R
RAX7, 2020-12-25
@RAX7

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question