TipsBlocks Web Technique Library

PRACTICAL WEB TIP

← Back to library

Palette One — Back to Palette One

A responsive color palette fans open and returns visitors to the first swatch.

Design Preview

See the design above before trying the scroll interaction.

LOOK CLOSELY
IN PAGE CONTEXT

Live Demo

Press Try scrolling inside the frame, or scroll inside it. The button appears at the lower right and returns you to the top.

Source Code

Copy the HTML, CSS or JavaScript you need for your project.

HTML
<button aria-label="色見本の先頭、ページのトップへ戻る" class="btt-control btt-2094 btt-hidden" data-btt="" type="button"><span aria-hidden="true" class="swatch-group"><i class="swatch s1"></i><i class="swatch s2"></i><i class="swatch s3"></i><i class="swatch s4"></i></span><span class="palette-label"><b>01 / FIRST COLOR</b><small>BACK TO TOP</small></span><span class="palette-counter" data-state="">03 / 04</span></button>
CSS
 .btt-control{box-sizing:border-box;appearance:none;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent}.btt-control:focus-visible{outline:3px solid #e6a643;outline-offset:5px}.btt-hidden{opacity:0;visibility:hidden;pointer-events:none}.btt-visible{opacity:1;visibility:visible;pointer-events:auto} @media(prefers-reduced-motion:reduce){.btt-control,.btt-control *{animation-duration:.01ms!important;transition-duration:.01ms!important}}
 .btt-2094{position:fixed;left:clamp(14px,3vw,46px);bottom:27px;z-index:40;width:196px;height:118px;border:0;border-radius:7px;background:#faf9f4;color:#1f3432;box-shadow:0 12px 35px #0003;padding:13px 14px;display:flex;flex-direction:column;gap:9px;align-items:stretch;opacity:0;transform:translateY(20px);transition:opacity .3s,transform .3s,visibility .3s}.btt-2094.btt-visible{opacity:1;transform:none}.swatch-group{display:flex;gap:5px;height:43px;width:100%;transition:transform .3s}.swatch{display:block;width:25%;border-radius:2px;background:#cf745a;transition:transform .35s}.swatch.s2{background:#e6bd80}.swatch.s3{background:#7b9997}.swatch.s4{background:#283e51}.swatch.is-selected{outline:2px solid #171f21;outline-offset:2px}.palette-label{display:flex;flex-direction:column;align-items:start;gap:5px}.palette-label b{font:800 12px/1 Arial;letter-spacing:.08em}.palette-label small{font:800 10px/1 Arial;letter-spacing:.12em}.palette-counter{position:absolute;right:12px;bottom:13px;font:700 10px/1 monospace;color:#667573}.btt-2094:hover{transform:translateY(-7px)}.btt-2094:hover .swatch-group i:nth-child(1){transform:translateY(-5px)}.btt-2094:hover .swatch-group i:nth-child(3){transform:translateY(4px)}@media(max-width:600px){.btt-2094{left:12px;bottom:17px;width:175px;height:110px;padding:10px 11px}.swatch-group{height:40px}.palette-label b{font-size:11px}.palette-label small{font-size:9px}}
/* Field QA / positioning and responsive readability */
@media(max-width:600px){.btt-2094{width:162px;height:97px;left:10px;bottom:14px;padding:8px 10px;gap:5px}.swatch-group{height:36px}.palette-label{gap:3px}.palette-label b{font-size:10px}.palette-label small{font-size:8.5px}.palette-counter{font-size:8px;right:10px;bottom:10px}}
JavaScript
(()=>{'use strict';const el=document.querySelector('[data-btt]');if(!el)return;const footerOnly=false;const reduce=window.matchMedia('(prefers-reduced-motion: reduce)');let raf=0;function update(){raf=0;const p=Math.max(0,Math.min(1,window.scrollY/Math.max(1,document.documentElement.scrollHeight-window.innerHeight)));if(!footerOnly){const shown=window.scrollY>170;el.classList.toggle('btt-visible',shown);el.classList.toggle('btt-hidden',!shown);el.tabIndex=shown?0:-1;el.setAttribute('aria-hidden',String(!shown));}el.style.setProperty('--progress',p.toFixed(3));const field=el.querySelector('[data-state]');const i=Math.min(3,Math.floor(p*4));el.querySelectorAll('.swatch').forEach((n,k)=>n.classList.toggle('is-selected',k===i));if(field)field.textContent=String(i+1).padStart(2,'0')+' / 04';}function onScroll(){if(!raf)raf=requestAnimationFrame(update)}window.addEventListener('scroll',onScroll,{passive:true});window.addEventListener('resize',onScroll,{passive:true});el.addEventListener('click',()=>{el.classList.add('is-going');window.scrollTo({top:0,behavior:reduce.matches?'auto':'smooth'});window.setTimeout(()=>el.classList.remove('is-going'),650)});update()})();

How to Use

Insert the HTML button near the end of body, load the CSS, and include JavaScript using defer. Test scrolling, returning to the top, and positioning on mobile.

Use Case

Design studios, branding and art.

Technical Notes

Keep controls usable on touch devices. Test keyboard focus and reduced-motion preferences.

Mobile:Check tap target, visibility and positioning on small screens.

Browser:Designed for current Chrome, Edge, Firefox and Safari.

Reduced Motion:CSS animations respect the reduced-motion preference.