【问题标题】:Fullpage.js Slide horizontal on scrollFullpage.js 在滚动时水平滑动
【发布时间】:2015-12-31 10:28:08
【问题描述】:

我使用fullpage.js实现纵横滚动。

当我在第 2 部分滚动时,我希望滑块滑动。

类似这个website 的功能

这是我的代码:

$(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);
                    }
                }
            });
        }
    }
});

});

对于视觉:

【问题讨论】:

标签: javascript jquery html horizontal-scrolling fullpage.js


【解决方案1】:

终于搞定了:

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;

    }

});

});

【讨论】:

    【解决方案2】:

    这里有一个更详细的例子,它恢复了@undefinedtoken 的代码:)

    计划:

    示例代码:

    $(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--;
                        }
                    }
                }
            });
        });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多