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

              
                <div class="container">
    <section class="slide">
        <div class="slide__content">
            <h1>ミツエーリンクスについて</h1>
        </div>
        <p class="slide__ruby">本日はミツエーリンクスについてお話します。</p>
    </section>
    <section class="slide">
        <div class="slide__content">
            <h2>会社情報</h2>
        </div>
        <p class="slide__ruby">ミツエーリンクスは、顧客企業さまのビジネスを持続的発展に導く、国内屈指のコミュニケーション・デザイン・カンパニーです。</p>
    </section>
</div>
              
            
!

CSS

              
                * {
    margin: 0;
    padding: 0;
}
html {
    height: 100%;
}
body {
    height: 100%;
}
body.is-presentation .slide__ruby {
    display: none;
}
.container {
    height: 100%;
    display: flex;
    scroll-snap-type: x mandatory;
    overflow: auto;
}
.slide {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 0.2fr;
    min-width: 100%;
    scroll-snap-align: start;
}
.slide__content {
    display: grid;
    place-items: center;
}
.slide__ruby {
    background: #eee;
    padding: 20px;
}
              
            
!

JS

              
                let currentPageIdx = 0;
const bc = new BroadcastChannel('app');
const container = document.querySelector('.container');
const nodeListOfSlide = document.querySelectorAll('.slide');
const isPresentation = /presentation/.test(location.search);
/**
 * 各スライドのid属性にindex番号を割り振る
 * @returns {void}
 */
const setIndexOnSlide = () => {
    nodeListOfSlide.forEach((slide, i) => {
        slide.id = `page-index_${i}`;
    });
};
/**
 * スライドの切り替わりを監視し、他閲覧コンテキストにスライドの切り替え信号を送る
 * @returns {void}
 */
const observeSlide = () => {
    const slideObserver = new IntersectionObserver((entries) => {
        for (entry of entries) {
            if (entry.isIntersecting) {
                const pageIdx = entry.target.id.split('_')[1];
                currentPageIdx = pageIdx;
                bc.postMessage({name: 'changeSlide', value: pageIdx});
            }
        }
    }, {threshold: 1});

    nodeListOfSlide.forEach((slide) => {
        slideObserver.observe(slide);
    });
};
/**
 * 他閲覧コンテキストからメッセージを受け取った時の処理
 * @param {MessageEvent} e
 * @returns {void}
 */
const onMessage = (e) => {
    const {name, value} = e.data;

    if (name === 'pageSyncRequest' && !isPresentation) {
        bc.postMessage({name: 'syncCurrentPageIdx', value: currentPageIdx});
    }
    if (name === 'changeSlide') {
        currentPageIdx = value;

        const target = document.querySelector(`#page-index_${value}`);
        container.scrollBy({
            left: target.getBoundingClientRect().left,
            behavior: 'smooth'
        });
    }
};
/**
 * 初期化
 * @returns {void}
 */
const init = () => {
    setIndexOnSlide();
    observeSlide();

    bc.onmessage = onMessage

    if (isPresentation) {
        document.body.classList.add('is-presentation');
        bc.postMessage({name: 'pageSyncRequest', value: null});
    }
};

init();
})();
              
            
!
999px

Console