TipsBlocks Web Technique Library

PRACTICAL WEB TIP

← ライブラリへ戻る

Index Return — 企業サイト

右端のインデックスに収めた戻り導線。線と数字の変化だけで伝える。

デザインプレビュー

まず形と大きさを確認。実際の動作は下のLive Demoで試せます。

造形とホバー
サイトでの実寸イメージ

Live Demo

枠内の「動作を試す」を押すか、枠の中をスクロールしてください。右下にボタンが現れ、クリックすると先頭へ戻ります。

Source Code

必要なコードをコピーして実装に利用できます。

HTML
<!-- TB-2064 / Index Return / 企業サイト | paste before the closing body tag (inside the footer for TB-2069) -->
<button aria-label="ページの先頭へ戻る" class="btt indexer tb-btt-2064" type="button"><span class="ind-no">00</span><span class="ind-line"></span><span class="ind-text">INDEX</span></button>
CSS
/* 2064 / production button rules only */
.tb-btt-2064{box-sizing:border-box;font:inherit;cursor:pointer}.tb-btt-2064 :is(span,i,em,b,small,img){box-sizing:border-box}
.btt.tb-btt-2064{position:fixed;z-index:90;border:0;cursor:pointer;-webkit-tap-highlight-color:transparent;opacity:0;visibility:hidden;pointer-events:none;transition:opacity .28s ease,visibility .28s ease,transform .35s ease}.btt.tb-btt-2064:focus-visible{outline:3px solid #f0af43;outline-offset:5px}.tb-btt-2064 .indexer{right:24px;top:43%;width:73px;height:146px;background:#f8fbf9;color:#325356;border:1px solid #a4b4b0;box-shadow:0 12px 28px #2437341a;padding:17px 10px;display:flex;flex-direction:column;align-items:center;justify-content:space-between}.tb-btt-2064 .ind-no{font:400 33px/1 Georgia,serif;letter-spacing:-.12em}.tb-btt-2064 .ind-line{display:block;width:1px;height:34px;background:#91a59d;transition:height .3s,width .3s}.tb-btt-2064 .ind-text{font:700 10px/1 Arial;letter-spacing:.12em;writing-mode:vertical-rl}.tb-btt-2064 .indexer:hover{background:#325356;color:#fff;transform:translateY(-8px)}.tb-btt-2064 .indexer:hover .ind-line{background:#fff;height:22px;width:18px}@media  (max-width:600px){.tb-btt-2064 .indexer{right:12px;top:auto;bottom:22px;width:58px;height:114px;padding:12px 8px}.tb-btt-2064 .ind-no{font-size:26px}.tb-btt-2064 .ind-line{height:20px}}

@media(prefers-reduced-motion:reduce){.tb-btt-2064,.tb-btt-2064 *{animation-duration:.01ms!important;transition-duration:.01ms!important}}
JavaScript
(()=>{'use strict';const target=document.querySelector('.btt, .footer-return');if(!target)return;const isFooter=target.classList.contains('footer-return');const reduced=matchMedia('(prefers-reduced-motion: reduce)');let active=false;const update=()=>{const y=window.scrollY;const p=Math.max(0,Math.min(1,y/Math.max(1,document.documentElement.scrollHeight-innerHeight)));if(!isFooter){const visible=y>160;target.classList.toggle('is-visible',visible);target.setAttribute('aria-hidden',String(!visible));target.tabIndex=visible?0:-1;}target.style.setProperty('--pct',p.toFixed(3));const txt=target.querySelector('[data-progress]');if(txt)txt.textContent=String(Math.round(100*p)).padStart(2,'0')+'%';};const scroll=()=>{if(active)return;active=true;requestAnimationFrame(()=>{active=false;update()})};target.addEventListener('click',()=>window.scrollTo({top:0,behavior:reduced.matches?'instant':'smooth'}));addEventListener('scroll',scroll,{passive:true});addEventListener('resize',scroll,{passive:true});update();})();

How to Use

HTMLのボタンをbody末尾付近へ設置し、CSSを読み込んでください。JavaScriptもdeferで読み込みます。実ページでスクロール後の表示・先頭復帰・スマートフォンでの位置を確認してください。

Use Case

峰と木 建築設計室など、サイト全体の世界観と一体になったページトップ導線。

Technical Notes

ホバー非対応端末でも主要操作ができるようにし、キーボードフォーカス時の表示と動き軽減設定を確認してください。

Mobile:390px幅も含むモバイル表示を確認してください。

Browser:Chrome・Edge・Firefox・Safari等の現行ブラウザを対象とします。

Reduced Motion:prefers-reduced-motion環境ではCSSアニメーションを抑制します。