微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Locomotive Scroll - 从水平到垂直和向后切换

如何解决Locomotive Scroll - 从水平到垂直和向后切换

我正在使用 Locomotive-Scroll (https://locomotivemtl.github.io/locomotive-scroll/) 进行平滑和水平滚动,这很容易而且效果很好。不过,我也想整合一段垂直滚动。

Visual Explanation

我尝试了很多方法,但没有一个完全有效。我主要面临三个问题:

  • 我不明白为什么我的解决方案在某种程度上有效,而且我找不到任何关于 locomotive-scroll 的教程,而不是添加 data-scroll 属性
  • 我没有找到将垂直滚动方向从向下更改为向上的方法
  • 如果我调整窗口大小,机车滚动刹车,只能通过重新加载来恢复

我目前的解决方案(我认为自己是初学者):

const scroller = new LocomotiveScroll({
    el: document.querySelector('#scrollable'),smooth: true,direction: 'horizontal'
});
* {
    Box-sizing: border-Box;
    margin: 0;
    padding: 0;
    font-family: 'Helvetica Neue',sans-serif;
    font-size: 2vh;
}

.section {
    height: 100vh;

}

#section-one {
    width: 100vw;
}

#section-two {
    width: 400vh;
    background-color: blanchedalmond;
}

#section-three {
    width: 100vw;
}

.heading {
    font-size: 5rem;
    font-weight: 500;
    text-transform: uppercase;
}

.home__statement {
    width: 100vw;
    position: relative;
}

.heading.one {
    position: absolute;
    left: 10vw;
    top: 25vh;
}

.heading.two {
    position: absolute;
    left: 10vw;
    top: 35vh;
}

.heading.three {
    position: absolute;
    left: 10vw;
    top: 45vh;
}

#sticky-container{
    width: 100vw;
    height: 100vh;
    background-color: cadetblue;
}

.vertical-canvas {
    position: absolute;
    top: -300vh;
    height: 400vh;
    width: 100vw;
    background-image: linear-gradient(red,yellow);
}

.example-1 {
    height: 50%;
    width: 100vw;
    background-color:rgba(175,18,0.3);;
}

.elem {
    width: 100px;
    height: 100px;
    background-color: cornsilk;
}

.example-2 {
    height: 25%;
    width: 100vw;
    background-color: rgba(46,165,46,0.3);
}

.example-3 {
    height: 25%;
    width: 100vw;
    background-color: rgba(75,92,168,0.3);
}
    <div id="scrollable" data-scroll-container>

        <section class="section" id="section-one" data-scroll-section>

            <div class="home__statement">
                <span class="heading one" id="statement__line-one">Some text blabla</span>
            <div>

        </section>
        
        <section class="section" id="section-two" data-scroll-section>

            <div id="sticky-container"
                data-scroll
                data-scroll-sticky
                data-scroll-target="#section-two"
                data-scroll-speed="-1">
                    <div class="vertical-canvas"
                        data-scroll
                        data-scroll-sticky
                        data-scroll-target="#section-two"
                        data-scroll-direction="vertical">
                        <div class="example-1" id="ex1">
                            <div class="elem"></div>
                        </div>
                        <div class="example-2"></div>
                        <div class="example-3"></div>
                    </div>
            <div>

        </section>

        <section class="section" id="section-three" data-scroll-section>

            <div class="home__statement">
                <span class="heading one" id="statement__line-one">Some text blabla</span>
            <div>

        </section>

解决方法

你不能同时初始化水平滚动和垂直滚动 [数据滚动容器]

想要实现的事情,可以用gsap scrollTrigger 但你必须implement scrollTrigger with locmotive

你可以做任何你想要的效果

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?