Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollify direction (UP & DOWN)

I'm using scrollify.js https://projects.lukehaas.me/scrollify/

I have everything working. But I have a pagination, that I was basically animating by adding an active class, depending on the page. But now the animation changed, and it depends on if you are scrolling from up to down or from down to up. So I will like to add a class of active.fromTop or active.fromDown. But I do not find anywhere in the documentation the option of knowing the direction on scroll.

$.scrollify({
     section: ".section-scroll",
     easing: "easeOutExpo",
     sectionName: false,
     scrollSpeed: 550,
     setHeights: false,
     offset: 0,
     before: function(e) {

        $('.pagination li').eq(e).addClass('active');

      },

});

Thanks for the help!

like image 689
Mario Sanchez Maselli Avatar asked Oct 16 '25 16:10

Mario Sanchez Maselli


2 Answers

There is no such feature, try this

$.scrollify({
     section: ".section-scroll",
     easing: "easeOutExpo",
     sectionName: false,
     scrollSpeed: 550,
     setHeights: false,
     offset: 0,
     afterRender:function(){
                $('body').attr('data-preIndex',0);
                },
     before: function(e) {
                var direction,preIndex;
                preIndex = parseInt($('body').attr('data-preIndex'));
                if (e > preIndex){
                    direction = "down";
                    }else{
                    direction = "up";
            }

            $('body').attr('data-preIndex',e);

            console.log( direction );            

            $('.pagination li').eq(e).addClass('active');

      },

});
like image 130
Michael Jason Avatar answered Oct 18 '25 07:10

Michael Jason


To add direction class to body, and little more concise:

$.scrollify({
    afterRender() {
        $('body').attr('data-pre-index', 0);
    },
    before(i) {
        const $body = $('body');
        let preIndex = parseInt($body.attr('data-pre-index'));
        let direction = i > preIndex ? 'down' : 'up';

        $body
            .attr('data-pre-index', i)
            .removeClass('up down')
            .addClass(direction);
    }
});
like image 34
Ali Klein Avatar answered Oct 18 '25 07:10

Ali Klein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!