viewport-checker icon indicating copy to clipboard operation
viewport-checker copied to clipboard

Add data-attribute for delay start animation

Open Romancho opened this issue 5 years ago • 1 comments

It will be very comfortable to set data-vp-add-class-delay & data-vp-remove-class-delay in html to create complex animation scenarios.

Romancho avatar Jul 28 '19 10:07 Romancho

I use https://animejs.com/ and then in particular the timeline function (https://animejs.com/documentation/#timelineBasics) in the callbackFunction of viewportChecker() to create complexed delayed animations.

Example:

$('.product').viewportChecker({
    offset: 300,
    callbackFunction: function () {
        anime.timeline().add({
            targets: '.product.visible .character',
            opacity: [0, 1],
            translateY: ['32px', 0],
            delay: anime.stagger(40, {
                direction: 'reverse'
            }),
        }, 600).add({
            targets: '.product.visible .product-photo img',
            opacity: [
                { value: 0, duration: 300, delay: 75 },
                { value: 1, duration: 300, delay: 75 }
            ],
            translateX: [
                { value: '-100%', duration: 300 },
                { value: 0, duration: 300 }
            ],
            easing: 'easeInQuad',
        }, '-=1500').add({
            targets: '.product.visible .el',
            opacity: [0, 1],
            translateY: ['32px', 0],
            delay: anime.stagger(50),
            complete: function() {
                $('.product.visible').removeClass('visible');
            },
        }, '-=1000')
    },
});

gentle-media avatar Oct 26 '19 16:10 gentle-media