TipsBlocks Web Technique Library

PRACTICAL WEB TIP

← ライブラリへ戻る

Yuzu Bottle — 商品の一部

画面をスクロールすると瓶が現れ、泡が浮かぶ。ボタンは商品そのもの。

デザインプレビュー

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

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

Live Demo

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

Source Code

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

HTML
<!-- TB-2061 / Yuzu Bottle / 商品の一部 | paste before the closing body tag (inside the footer for TB-2069) -->
<button aria-label="ページの先頭へ戻る" class="btt bottle tb-btt-2061" type="button"><i class="bubbles"></i><img alt="" src="https://tipsblocks.com/wp-content/uploads/tipsblocks-btt-2061-2072/assets/yuzu.webp"><span class="bottle-note">back to beginning</span></img></button>
CSS
/* 2061 / production button rules only */
.tb-btt-2061{box-sizing:border-box;font:inherit;cursor:pointer}.tb-btt-2061 :is(span,i,em,b,small,img){box-sizing:border-box}
.btt.tb-btt-2061{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-2061:focus-visible{outline:3px solid #f0af43;outline-offset:5px}.tb-btt-2061 .bottle{right:22px;bottom:22px;width:98px;min-height:145px;background:transparent}.tb-btt-2061 .bottle img{width:90px;display:block;margin:auto;filter:drop-shadow(0 10px 8px #57482d34);transition:transform .5s cubic-bezier(.2,.7,.2,1)}.tb-btt-2061 .bottle:hover img{transform:translateY(-13px) rotate(-5deg)}.tb-btt-2061 .bottle-note{font:700 9px/1.2 Arial,sans-serif;letter-spacing:.045em;display:block;background:#fff8dfed;color:#4e593e;border-radius:12px;padding:5px 4px;box-shadow:0 3px 12px #4e593e28}.tb-btt-2061 .bubbles{position:absolute;top:-11px;left:25px;width:42px;height:42px;background:radial-gradient(circle at 20% 60%,#f7de7b 0 3px,transparent 4px),radial-gradient(circle at 50% 20%,#f7de7b 0 4px,transparent 5px),radial-gradient(circle at 80% 65%,#f7de7b 0 3px,transparent 4px);animation:tb-btt-2061-rise 2.8s ease-in-out infinite}@media  (max-width:600px){.tb-btt-2061 .bottle{right:12px;bottom:16px;width:85px}.tb-btt-2061 .bottle img{width:76px}}
@keyframes tb-btt-2061-rise{50%{transform:translateY(-16px);opacity:.35}}
@media(prefers-reduced-motion:reduce){.tb-btt-2061,.tb-btt-2061 *{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アニメーションを抑制します。