Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://unpkg.com/@dotlottie/player-component@latest/dist/dotlottie-player.mjs" type="module"></script>
<div class="p-storybook__wrapper">
        <div class="p-storybook__page">
            <div class="p-page__1">
                <div class="sky">
                    <div class="star"></div>
                    <div class="star"></div>
                    <div class="star"></div>
                    <div class="star"></div>
                    <div class="star"></div>
                </div>
                <h1>私のお気に入りの絵本</h1>
                <span>My favorite story book</span>
            </div>
            <div class="page-trigger">
            </div>
            <div class="anime-trigger">
            </div>
        </div>
        <div class="p-storybook__page">
            <div class="p-page p-page__2">
                <div class="p-page__bg">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page1/%E8%83%8C%E6%99%AF.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-people">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page1/%E4%BA%BA%E7%89%A9.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-tree">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page1/%E6%9C%A8%EF%BC%91.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-tree2">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page1/%E6%9C%A8%E3%81%A8%E8%8D%89.png?raw=true" alt="">
                </div>
                <div class="p-page__title js-title-1">
                </div>
            </div>
            <div class="p-storybook__page-text">
                <p>仲睦まじい兄妹ヘンゼルとグレーテルが、継母に森に捨てられ、魔女の住むお菓子の家に迷い込む物語。</p>
            </div>
            <div class="page-trigger">
            </div>
            <div class="anime-trigger">
            </div>
        </div>
        <div class="p-storybook__page">
            <div class="p-page p-page__3">
                <div class="p-page__bg">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page2/%E8%83%8C%E6%99%AF.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-people">
                    <img src="./src/assets/image/page2/桃太郎.png" alt="">
                </div>
                <div class="p-page__object p-page__2-people">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page2/%E6%A1%83%E5%A4%AA%E9%83%8E.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-people">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page2/%E7%8A%AC.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-people">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page2/%E7%8C%BF.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-tree">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page2/%E8%8D%89.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-tree2">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page2/%E8%8D%89%EF%BC%92.png?raw=true" alt="">
                </div>
                <div class="p-page__title js-title-2">
                </div>
            </div>
            <div class="p-storybook__page-text">
                <p>桃から生まれた男の子、「桃太郎」が仲間を引き連れて、鬼を討伐する物語。</p>
            </div>
            <div class="page-trigger">
            </div>
            <div class="anime-trigger">
            </div>
        </div>
        <div class="p-storybook__page">
            <div class="p-page p-page__4">
                <div class="p-page__bg">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page3/%E8%83%8C%E6%99%AF.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-people">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page3/%E3%82%B8%E3%83%A3%E3%83%83%E3%82%AF.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-tree">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page3/%E8%94%A6.png?raw=true" alt="">
                </div>
                <div class="p-page__object p-page__2-tree2">
                    <img src="https://github.com/hayuse-mochiya/code_pen_challenge/blob/feature/scroll/codepen/src/assets/image/page3/%E8%94%A6%EF%BC%92.png?raw=true" alt="">
                </div>
                <div class="p-page__title js-title-3">
                </div>
            </div>
            <div class="p-storybook__page-text">
                <p>ジャックが不思議な豆を手に入れて、空の上を探検する物語。</p>
            </div>
            <div class="page-trigger">
            </div>
            <div class="anime-trigger">
            </div>
        </div>
    </div>
              
            
!

CSS

              
                body, html {
    margin: 0;
    padding: 0;
    // overflow-x: hidden;
    height: 100%;
    // scroll-behavior: smooth;
    background-color: #110f5d;
}
* {
    box-sizing: border-box;
}
.p-page {
    width: 100vw;
    height: 100vh;
    transform-style: preserve-3d;
    animation: rotate 30s infinite;
    flex-shrink: 0;
    position: relative;
    &__title {
        position: absolute;
        top: 25%;
        left: 50%;
        translate: -50% -50%;
        transform: translate3d(0, 0, 600px);
        opacity: 0.8;
        display: none;
    }
    &__bg {
        position: absolute;
        top: 0;
        left: 0;
        object-fit: cover;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        &::after {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #110f5d;
            border-radius: 50%;
            transform-origin: center center;
            transition: scale 1s;
            scale: 300%;
            filter: blur(100px);
        }
    }
    &__object {
        position: absolute;
        top: 0;
        left: 0;
        opacity: 0;
        scale: 150%;
        transform: translate3d(0, 0, -500px);
        object-fit: cover;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        & > img {
        }
    }
    &__1 {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        background-color: #110f5d;
        flex-direction: column;
        & > h1 {
            font-size: 4rem;
            color: #fff;
            display: block;
            margin: 0;
            padding: 0;
        }
        & > span {
            display: block;
            color: #fff;
            font-size: 1.5rem;
        }
    }
    &__2 {
        & > dotlottie-player {
            // position: absolute;
            // top: 25%;
            // left: 50%;
            // translate: -50% -50%;
            // transform: translate3d(0, 0, 600px);
            // opacity: 0.8;
            // display: none;
        }
        &-people {
            transition: 1s 0.3s;
            opacity: 0;
            scale: 150%;
            transform: translate3d(0, 0, 2000px);
        }
        &-tree {
            transition: 1s 0.5s;
            opacity: 0;
            scale: 150%;
            transform: translate3d(0, 0, 2000px);
        }
        &-tree2 {
            transition: 1s 0.7s;
            opacity: 0;
            scale: 150%;
            transform: translate3d(0, 0, 2000px);
        }
    }
    &__3 {
        .p-page__title {
            left: 0;
            top: 5%;
            translate: 0 0;
            opacity: 1;
        }
    }
    &__4 {
        .p-page__title {
            opacity: 1;
            // mix-blend-mode: color-burn;
        }
    }
}

.p-storybook {
    $this: &;
    &__page {
        position: relative;
        width: 100vw;
        height: 100vh;
        // float: left;
        flex-shrink: 0;
        overflow: hidden;
        & > div {
            // width: 100%;
            // height: 100%;
            &:is(.page-trigger) {
                position: absolute;
                top: 50%;
                left: 30%;
                width: 10px;
                height: 10px;
                // background-color: #f00;
            }
            &:is(.anime-trigger) {
                position: absolute;
                top: 50%;
                right: 10%;
                width: 10px;
                height: 10px;
                // background-color: #f00;
            }
        }
        &-text {
            position: absolute;
            padding: 16px 16px;
            width: 100%;
            height: max-content !important;
            font-size: 1.7rem;
            color: white;
            bottom: 32px;
            opacity: 0;
            text-shadow: 1px 1px 10px #000;
            backdrop-filter: blur(0px);
            transition: backdrop-filter 3s;
            & > p {
                text-align: center;
                padding: 0;
                margin: 0;
            }
        }
        &:is(.anime-start) {
            .p-storybook__page-text {
                opacity: 1;
                backdrop-filter: blur(3px);
                span {
                    opacity: 0;
                    animation: fade-in 1s forwards;
                }
            }
            .p-page__object {
                // animation: 1s fadein forwards;
            }
            .p-page {
                &__bg {
                    &::after {
                        scale: 0%;
                    }
                }
                &__2 {
                    &-people {
                        // animation:1s 0.2s fadein forwards;
                        opacity: 1;
                        scale: 100%;
                        transform: translate3d(0, 0, 100px);
                    }
                    &-tree {
                        opacity: 1;
                        scale: 100%;
                        transform: translate3d(0, 0, 1000px);
                    }
                    &-tree2 {
                        opacity: 1;
                        scale: 100%;
                        transform: translate3d(0, 0, 500px);
                    }
                    & > dotlottie-player {
                    }
                }
                &__title {
                    display: block;
                }
            }

        }
    }
    &__wrapper {
        display: flex;
    }
}

.sky {
    position: absolute;
    width: 100%;
    height: 100%;
}

.star {
    position: absolute;
    width: 2px;
    height: 2px;
    background-color: white;
    border-radius: 50%;
    opacity: 0;
    animation: twinkle 5s infinite ease-in-out;
}

.star:nth-child(1) { top: 20%; left: 15%; }
.star:nth-child(2) { top: 40%; left: 30%; }
.star:nth-child(3) { top: 60%; left: 70%; }
.star:nth-child(4) { top: 80%; left: 50%; }
.star:nth-child(5) { top: 50%; left: 80%; }
/* Add more star positions as needed */

@keyframes twinkle {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}


@keyframes fade-in {
    to {
        opacity: 1;
    }
}


@keyframes rotate {
    0% {transform: rotateX(0deg) rotateY(0deg)}
    25% {transform: rotateX(0deg) rotateY(5deg)}
    75% {transform: rotateX(0deg) rotateY(-5deg)}
    100% {transform: rotateX(0deg) rotateY(0deg)}
  }

@keyframes fadein {
    0% {
        opacity: 0;
        scale: 150%;
        transform: translate3d(0, 0, -500px);
    }
    100% {
        opacity: 1;
        scale: 100%;
        transform: translate3d(0, 0, 0px);
    }
}
              
            
!

JS

              
                console.log("storybook");

let currentSection = 0;
let scrollPosition = 0;

let timeoutId: number | null = null;
const delay = 500; // 3秒

const titleData = [
    {
       class: 'js-title-1',
       logo: 'https://lottie.host/fe19e5b1-96f6-4ff1-a74a-6d96ded01bde/FYZjndTMH6.json'
    },
    {
        class: 'js-title-2',
        logo: 'https://lottie.host/b05dcea8-b4c2-4b91-9de5-3d903c07940a/kepiEk8xzj.json' ,
    },
    {
        class: 'js-title-3',
        logo: 'https://lottie.host/265f5cd6-0d0c-42b3-9ae6-a6919eeb9297/GslZuGRsk7.json' ,
    }
]

const logoDataFunc = () => {
    titleData.forEach((title) => {
        console.log(title.logo);
        const logoElm = document.querySelector(`.${title.class}`);
        const player = document.createElement("dotlottie-player");
        player.setAttribute('src', title.logo);
        player.setAttribute('background', 'transparent');
        player.setAttribute('speed', '1');
        player.setAttribute('autoplay', '');
        if (logoElm === null) return;
        logoElm.innerHTML = '';
        logoElm.appendChild(player);
    });
}


const sections: NodeListOf<HTMLElement> = document.querySelectorAll('.p-storybook__page');

const handleWheelEvent = (event: WheelEvent): void => {
    event.preventDefault(); // Prevent default scroll behavior
    // if (event.deltaY > 0) {
    //     console.log(event.deltaY);
    //     currentSection = Math.min(currentSection + 1, sections.length - 1);
    // } else {
    //     currentSection = Math.max(currentSection - 1, 0);
    // }
    // window.scrollTo
    // console.log(event.deltaY, '|||||', currentSection);
    currentSection += event.deltaY;
    if (currentSection < 0) currentSection = 0;
    if (currentSection > 4500) currentSection = 4500;
    // if (currentSection > 0) currentSection = 0;

    window.scrollTo({ left: currentSection });
    // currentSection = currentSection + event.deltaY;

};

const movePage = () => {
    const activePage = document.querySelector<HTMLElement>('.p-storybook__page.is-active');
    if (activePage === null) return;
    scrollPosition = activePage.offsetLeft;

    window.scrollTo({ left: scrollPosition, behavior: "smooth" });

    // currentSection = scrollPosition;
}
const onScrollEnd = () => {
    currentSection = scrollPosition;
  };
  
const scrollHandler = () => {
if (timeoutId !== null) {
    clearTimeout(timeoutId);
}
timeoutId = window.setTimeout(onScrollEnd, delay);
};
  
  
  
window.addEventListener('wheel', handleWheelEvent, { passive: false });
window.addEventListener('scroll', scrollHandler);
window.addEventListener('touchend', movePage);
window.addEventListener('scrollend', movePage);

const scrollIntersect = (entries: IntersectionObserverEntry[], observer: IntersectionObserver): void => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            entry.target.parentElement?.classList.add('is-active');
        } else {
            entry.target.parentElement?.classList.remove('is-active');
        }
    });
};

const animeIntersect = (entries: IntersectionObserverEntry[], observer: IntersectionObserver): void => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            logoDataFunc();
            entry.target.parentElement?.classList.add('anime-start');
            const textElement = document.querySelector('.anime-start .p-storybook__page-text p');
            if (textElement) {
                const text = textElement.textContent || '';
                textElement.textContent = '';

                text.split('').forEach((char, index) => {
                    const span = document.createElement('span');
                    span.textContent = char;
                    span.style.animationDelay = `${index * 0.1}s`;
                    textElement.appendChild(span);
                });
            }
        } else {
            entry.target.parentElement?.classList.remove('anime-start');
        }
    });
};

// Options for the IntersectionObserver
const options = {
    root: null,
    rootMargin: '0px',
    threshold: 0.1
};

// Create the IntersectionObserver
const scrollObserver = new IntersectionObserver(scrollIntersect, options);

// Observe each .page-trigger element
const pageTriggers = document.querySelectorAll('.page-trigger');
pageTriggers.forEach(trigger => scrollObserver.observe(trigger));

// Create the IntersectionObserver
const animeObserver = new IntersectionObserver(animeIntersect, options);

// Observe each .page-trigger element
const animeTriggers = document.querySelectorAll('.anime-trigger');
animeTriggers.forEach(trigger => animeObserver.observe(trigger));
              
            
!
999px

Console