Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                .wrapper
  #horizontal.block
    div(data-window-size)
      svg#svg-image.svg-image(
        xmlns="http://www.w3.org/2000/svg",
        xmlns:xlink="http://www.w3.org/1999/xlink",
        viewBox="0 0 4096 1365",
        data-width=4096,
        data-height=1365,
        data-window-fitting,
        data-fitting-no-left
      )
        mask#mask
          | <g id="circleMask" fill="#fff" transform="scale(0)" data-width="200" data-height="200"><path d="M100 0 0 100l24 24 76-76 76 76 24-24"/><path d="m166.794 133.591-66.409 66.408-67.18-67.18 66.408-66.41zm-67.181-30.117-29.344 29.345 29.345 29.342 29.344-29.342z"/></g>
        image(
          xmlns:xlink="http://www.w3.org/1999/xlink",
          xlink:href="https://tech-blog.arc-one.jp/wp/wp-content/uploads/2021/06/sf2-scaled.jpg",
          width="100%",
          height="100%",
          mask="url(#mask)"
        )
      img#actual-image.actual-image(
        src="https://tech-blog.arc-one.jp/wp/wp-content/uploads/2021/06/sf2-scaled.jpg",
        width=4096,
        height=1365,
        data-width=4096,
        data-height=1365,
        alt="",
        data-window-fitting,
        data-fitting-no-left,
        aria-hidden="true"
      )

              
            
!

CSS

              
                .wrapper
  width 100%
  overflow hidden
  
.svg-image
  position relative
  
  
[aria-hidden="true"]
  display: none
  
img
  max-width: none
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

const disable = (event: Event): void => {
  event.preventDefault();
};

const events = ["wheel", "touchmove"];

/**
 * スクロールイベントの禁止
 * @constructor
 */
const ScrollDisabled = (): void => {
  events.forEach((event: string) => {
    document.addEventListener(event, disable, { passive: false });
  });
};

/**
 * スクロールイベント禁止の解除
 * @constructor
 */
const ScrollEnabled = ():void => {
  events.forEach((event: string) => {
    document.removeEventListener(event, disable, { passive: false });
  });
};

class FittingElement {
  #elements = [];

  constructor() {
    this.update();
  }

  update(): void {
    this.#elements = document.querySelectorAll("[data-window-size]");
  }

  /**
   * 要素サイズの更新
   * @param w
   * @param h
   */
  setup(w: number, h: number) {
    this.#elements.forEach((elem: HTMLElement) => {
      elem.style.width = `${w}px`;
      elem.style.height = `${h}px`;
    });
  }
}

class WindowFittingElement {
  #elements = [];

  constructor() {
    this.update();
  }

  update(): void {
    this.#elements = document.querySelectorAll('[data-window-fitting]');
  }

  /**
   * 要素のフィッティング
   * @param width - ウィンドウ or ターゲット要素の横
   * @param height - ウィンドウ or ターゲット要素の縦
   */
  setup(width: number, height: number) {
    this.#elements.forEach((elem) => {
      const iw = parseInt(elem.getAttribute('data-width'), 10);
      const ih = parseInt(elem.getAttribute('data-height'), 10);

      const { cw, ch, cx, cy } = WindowFittingElement.result(
        width,
        height,
        iw,
        ih
      );

      const noLeft = elem.getAttribute('data-fitting-no-left') === '';

      elem.style.width = `${cw}px`;
      elem.style.height = `${ch}px`;
      //if (!noLeft) elem.style.left = `${cx}px`;
      elem.style.top = `${cy}px`;
    });
  }

  /**
   * 要素フィッティングの計算結果のみ返却
   * @param parentWidth
   * @param parentHeight
   * @param targetWidth
   * @param targetHeight
   * @returns {{cw: number, ch: number, cx: number, cy: number, scale: number}}
   */
  static result(parentWidth: number, parentHeight: number, targetWidth: number, targetHeight: number): {cw: number, ch: number, cx: number, cy: number, scale: number} {
    const ratioW = parentWidth / targetWidth;
    const ratioH = parentHeight / targetHeight;

    const scale = Math.max(ratioW, ratioH);

    const cw = targetWidth * scale;
    const ch = targetHeight * scale;

    return {
      cw,
      ch,
      cx: -((cw - parentWidth) / 2),
      cy: -((ch - parentHeight) / 2),
      scale
    };
  }
}

// スクロールイベントの禁止
ScrollDisabled();

const blocks = new FittingElement();
const windowFittingElements = new WindowFittingElement();

const svg = document.querySelector('#svg-image');
const maskElem = document.querySelector('#circleMask');
const maskElemSize = {
  boxWidth: parseInt(svg.getAttribute('data-width'), 10),
  boxHeight: parseInt(svg.getAttribute('data-height'), 10),
  width: maskElem.dataset.width,
  height: maskElem.dataset.height
};

const actualImage = document.querySelector('#actual-image');
const horizontal = document.querySelector('#horizontal');

/**
 * マスク部分を表示領域の中心に表示する
 * @param width
 * @param height
 */
const maskElemCalc = (width: number, height: number) => {
  const { cw } = WindowFittingElement.result(
    width,
    height,
    maskElemSize.boxWidth,
    maskElemSize.boxHeight
  );

  const maskPos = {
    x: (width * (maskElemSize.boxWidth / cw)) / 2 - maskElemSize.width / 2,
    y: maskElemSize.boxHeight / 2 - maskElemSize.height / 2
  };

  maskElem.setAttribute('transform', `translate(${maskPos.x}, ${maskPos.y})`);
};

const _width = document.documentElement.clientWidth
const _height = document.documentElement.clientHeight

blocks.setup(_width, _height)
windowFittingElements.setup(_width, _height)
maskElemCalc(_width, _height)
gsap.set('#circleMask', {
  scale: 1,
  transformOrigin: 'center center'
})

gsap.to(horizontal, {
    id: 'horizontal',
    xPercent: -100 * ((parseFloat(svg.style.width) - _width) / _width),
    ease: 'none',
    scrollTrigger: {
      id: 'horizontal-scroll',
      trigger: horizontal,
      pin: true,
      scrub: true,
      snap: false,
      start: 'top top',
      end: () => `+=${horizontal.offsetWidth}`,
      invalidateOnRefresh: true,
      anticipatePin: 0,
    }
  });

gsap
  .to('#circleMask', {
    scale: 250,
    delay: 2,
    transformOrigin: 'center center',
    duration: 4
  })
  .then(() => {
    actualImage.setAttribute('aria-hidden', 'false');
    svg.setAttribute('aria-hidden', 'true');
    // スクロールイベント禁止解除
    ScrollEnabled();
  });


              
            
!
999px

Console