2

私は Locomotive-Scroll ( https://locomotivemtl.github.io/locomotive-scroll/ ) を使用して、スムーズで水平方向のスクロールを行います。これは簡単で、うまく機能します。ただし、縦スクロールのセクションも統合したいと思います。

視覚的な説明

私は多くのことを試しましたが、どれも完全に機能しません。私は主に3つの問題に直面しています:

  • なぜ私のソリューションがある程度機能するのか理解できず、データスクロールプロパティを追加するよりも先に進む機関車スクロールに関するチュートリアルが見つかりません
  • 垂直スクロールの方向を下から上に変更する方法が見つかりませんでした
  • ウィンドウのサイズを変更すると、機関車のスクロール ブレーキがかかり、リロードによってのみ復元できます

私の現在の解決策(私は自分自身を初心者だと考えています):

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, 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>

4

1 に答える 1