<div class="scroll-anim-29" id="js-scroll-anim-29">
    <div class="scroll-anim-29__bg"></div>
    <div class="scroll-anim-29__main"></div>
</div>
.scroll-anim-29#js-scroll-anim-29
  .scroll-anim-29__bg
  .scroll-anim-29__main
{
  "text": "テキストが入ります。テキストが入ります。テキストが入ります。"
}
  • Content:
    $BLOCK_NAME: '.scroll-anim-29';
    
    // 変数
    
    #{ $BLOCK_NAME } {
      width: 100%;
      height: 500px;
      position: relative;
    
      &__bg {
        width: 100%;
        height: 100%;
        background: #000;
      }
    
      &__main {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        width: 300px;
        height: 100%;
        background: #f00;
        transform: scale(0.5);
      }
    }
    
  • URL: /components/raw/scroll-anim29/scroll-anim29.scss
  • Filesystem Path: src/components/scroll-anims/scroll-anim29/scroll-anim29.scss
  • Size: 389 Bytes
  • Content:
    'use strict';
    
    import { gsap } from 'gsap';
    import { ScrollTrigger } from 'gsap/ScrollTrigger';
    gsap.registerPlugin(ScrollTrigger);
    
    export const scrollAnim29 = () => {
      const anim = new Anim29('js-scroll-anim-29');
      anim.init();
    };
    
    class Anim29 {
      el: HTMLElement;
      bgEl: HTMLElement;
      mainEl: HTMLElement;
      constructor(elId: string) {
        this.el = document.getElementById(elId);
        if (!this.el) return;
        this.bgEl = this.el.querySelector('.scroll-anim-29__bg');
        this.mainEl = this.el.querySelector('.scroll-anim-29__main');
      }
    
      /**
       * 初期化
       */
      init(): void {
        if (!this.el) return;
        this.scrollHandler();
      }
    
      /**
       * スクロール連動のイベント設定
       */
      scrollHandler(): void {
        // 背景のアニメーション
        gsap.to(this.bgEl, {
          scrollTrigger: {
            trigger: this.el,
            start: 'top bottom',
            end: 'bottom top',
            scrub: 0.3,
          },
          scale: 0.5,
        });
        // メインのアニメーション
        gsap.to(this.mainEl, {
          scrollTrigger: {
            trigger: this.el,
            start: 'top bottom',
            end: 'bottom top',
            scrub: 0.3,
          },
          scale: 1,
        });
      }
    }
    
  • URL: /components/raw/scroll-anim29/scroll-anim29.ts
  • Filesystem Path: src/components/scroll-anims/scroll-anim29/scroll-anim29.ts
  • Size: 1.2 KB