TipsBlocks Web Technique Library

PRACTICAL WEB TIP

← ライブラリへ戻る

Cinema Ticket Return — 映画チケット半券型

灯映シネマのサイトに合わせたBack to Top。映画チケット半券型を採用し、スクロール後の表示とページ先頭への復帰を提供します。

デザインプレビュー

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

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

Live Demo

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

Source Code

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

HTML
<button aria-label="ページの先頭へ戻る" class="back-top back-top-2097 tb-btt-button" title="ページの先頭へ戻る" type="button"><span aria-hidden="true" class="ticket-cut">▤</span><span aria-hidden="true" class="btt-symbol">↑</span><span class="btt-main">上へ戻る</span><span class="btt-meta">BACK TO TOP</span><span aria-hidden="true" class="ticket-code">№ 2097</span></button>
CSS
/* TIPSBLOCKS Back to Top — standalone control only. */
.tb-btt-button,.tb-btt-button *,.tb-btt-button *::before,.tb-btt-button *::after{box-sizing:border-box}
.tb-btt-button{font-family:"Noto Sans JP","Hiragino Kaku Gothic ProN","Yu Gothic",system-ui,sans-serif;--accent:#26393b}
.tb-btt-button:focus-visible{outline:3px solid #edb45f;outline-offset:4px}
@media(prefers-reduced-motion:reduce){.tb-btt-button,.tb-btt-button *{animation-duration:.01ms!important;transition-duration:.01ms!important}}
.back-top{font-family:inherit;appearance:none;border:0;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-direction:column;position:fixed;z-index:30;opacity:0;visibility:hidden;pointer-events:none;transform:translateY(14px);transition:opacity .28s,transform .28s,visibility .28s;isolation:isolate}
.back-top.is-visible{opacity:1;visibility:visible;pointer-events:auto;transform:translateY(0)}
.back-top.is-returning{pointer-events:none}
.back-top .btt-symbol{font-weight:450;font-size:27px;line-height:1}
.back-top .btt-main{font-weight:750;line-height:1.45;text-align:center;letter-spacing:.06em}
.back-top .btt-meta{font-size:9px;line-height:1.4;letter-spacing:.11em;text-align:center}
.back-top:hover{filter:brightness(1.1)}
@media (max-width:650px){.back-top{max-width:112px}}
.back-top-2097{right:27px;bottom:40px;width:114px;min-height:130px;padding:13px 11px;background:#f3dfcd;color:#6f1c29;border:3px double #782b38;transform:translateY(15px) rotate(-7deg);box-shadow:0 8px 18px #0005;clip-path:polygon(0 0,5% 3%,0 7%,0 93%,5% 97%,0 100%,100% 100%,95% 97%,100% 93%,100% 7%,95% 3%,100% 0)}
.back-top-2097.is-visible{transform:rotate(-7deg)}
.back-top-2097:hover{transform:rotate(-2deg) translateY(-8px)}
.back-top-2097 .btt-symbol{font-size:30px}
.back-top-2097 .ticket-cut{border:2px solid #782b38;border-radius:3px;padding:0 8px;font-size:18px;margin-bottom:3px}
.back-top-2097 .btt-main{font-size:13px}
.back-top-2097 .ticket-code{font-size:8px;letter-spacing:.2em;margin-top:4px}
@keyframes flame{to{transform:scaleY(1.45);background:#ffc34a}}
@keyframes buoybob{to{translate:0 -5px}}
@media (max-width:650px){.back-top-2097{width:86px;min-height:103px;right:8px;bottom:9px}
.back-top-2097 .ticket-cut{font-size:13px}
.back-top-2097 .btt-meta,.back-top-2097 .ticket-code{font-size:7px}}
JavaScript
/** TIPSBLOCKS TB-2097 — independent Back to Top. */
(()=>{'use strict';
 const control=document.querySelector('.tb-btt-button.back-top-2097');if(!control)return;
 const footer=false;
 const reduced=window.matchMedia('(prefers-reduced-motion: reduce)');
 const threshold=190;
 let raf=0;
 function update(){raf=0;const visible=footer||window.scrollY>threshold;
 control.classList.toggle('is-visible',visible);
 if(!footer){control.setAttribute('aria-hidden',String(!visible));control.tabIndex=visible?0:-1;}
 }
 window.addEventListener('scroll',()=>{if(!raf)raf=requestAnimationFrame(update)},{passive:true});
 window.addEventListener('resize',update,{passive:true});
 control.addEventListener('click',()=>{control.classList.add('is-returning');
 window.scrollTo({top:0,behavior:reduced.matches?'instant':'smooth'});
 if(reduced.matches)control.classList.remove('is-returning');
 else {const onStop=()=>{if(window.scrollY<=3){control.classList.remove('is-returning');window.removeEventListener('scroll',onStop)}};
 window.addEventListener('scroll',onStop,{passive:true});}
 });
 update();
})();

How to Use

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

Use Case

映画館、映像メディア、エンターテインメントのサイト

Technical Notes

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

Mobile:タップ領域、表示サイズ、コンテンツとの重なりを確認してください。

Browser:現行のChrome、Edge、Firefox、Safariを想定しています。

Reduced Motion:prefers-reduced-motionの設定を尊重して先頭復帰の動きを抑えます。