Fullpage.js Slide horizontal on scroll
Asked Answered
M

2

14

Im using fullpage.js to achieve vertical and horizontal scroll.

i want the slider to slide when i scroll on Section 2.

Functionality similar to this website

Here's my code :

$(document).ready(function() {
$('#fullpage').fullpage({
    sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', 'whitesmoke', '#ccddff'],
    anchors: ['firstPage', 'secondPage', '3rdPage', '4thpage', 'lastPage'],
    menu: '#menu',
    css3: true,
    loop: false,
    afterLoad: function(anchorLink, index) {
        var loadedSection = $(this);

        //using index
        if (index == 3) {
            $.fn.fullpage.setAllowScrolling(false);
            $.fn.fullpage.setKeyboardScrolling(false);
            $(window).bind('mousewheel DOMMouseScroll', function(event) {
                if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
                    $(".fp-prev").click();
                    if ($(".fp-slide:first-child").hasClass("active")) {
                        $.fn.fullpage.setAllowScrolling(true);
                        $.fn.fullpage.setKeyboardScrolling(true);
                    }
                } else {
                    $(".fp-next").click();
                    if ($(".fp-slide:last-child").hasClass("active")) {
                        $.fn.fullpage.setAllowScrolling(true);
                        $.fn.fullpage.setKeyboardScrolling(true);
                    }
                }
            });
        }
    }
});

});

For visual :enter image description here

Middling answered 3/10, 2015 at 7:54 Comment(1)
That's now possible with the fullpage.js extension scrollHorizontallyKumasi
M
10

Finally got it working :

var slideIndex  = 1,
sliding     = false;

$(document).ready(function() {

$('#fullpage').fullpage({

    sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', 'whitesmoke', '#ccddff'],
    scrollingSpeed:1000,
    css3: true,

    onLeave: function(index, nextIndex, direction) {

        if(index == 2 && !sliding) {

            if(direction == 'down' && slideIndex < 5) {

                sliding = true;
                $.fn.fullpage.moveSlideRight();
                slideIndex++;
                return false;

            } else if(direction == 'up' && slideIndex > 1) {

                sliding = true;
                $.fn.fullpage.moveSlideLeft();
                slideIndex--;
                return false;

            }

        } else if(sliding) {

            return false;

        }

    },

    afterSlideLoad: function(anchorLink, index, slideAnchor, slideIndex) {

        sliding = false;

    }

});

});

Middling answered 4/10, 2015 at 14:6 Comment(0)
P
3

Here is a little bit more elaborate example which resumes the code of @undefinedtoken :)

Plan: enter image description here

Exemple Code :

$(document).ready(function () {

        var slideIndex2 = 1, sliding = false;

        $('#fullpage').fullpage({

            // ...your cutom code...

            //events
            onLeave       : function (index, nextIndex, direction) {
                if (index == 3 && !sliding) {
                    if (direction == 'down' && slideIndex2 < 4) {
                        sliding = true;
                        $.fn.fullpage.moveSlideRight();
                        return false;
                    } else if (direction == 'up' && slideIndex2 > 1) {
                        sliding = true;
                        $.fn.fullpage.moveSlideLeft();
                        return false;
                    }
                } else if (sliding) {
                    return false;
                }

            },
            afterSlideLoad: function (anchorLink, index, slideAnchor, slideIndex) {
                sliding = false;
            },
            onSlideLeave  : function (anchorLink, index, slideIndex, direction, nextSlideIndex) {
                if (index == 3) {
                    if (direction == 'right') {
                        sliding = true;
                        slideIndex2++;
                    }

                    if (direction == 'left') {
                        sliding = true;
                        slideIndex2--;
                    }
                }
            }
        });
    });
Pee answered 7/8, 2016 at 21:54 Comment(1)
That's now possible with the fullpage.js extension scrollHorizontallyKumasi

© 2022 - 2024 — McMap. All rights reserved.