网格地平线
布局区块HTML/CSS已复制 0 次
八十年代蒸汽波风格的整屏背景:一颗落日压在透视网格的地平线上,网格向观者推进,扫描线可选。太阳半径、黑线粗细、地平线高度、网格密度、推进周期都可调;黑线与扫描线默认都为 0,即干净的现代版,拉起来才回到复古质感。网格主色与冷色点缀各自独立取色。鼠标移动时整个场景轻微转头、太阳反向位移。给的是去掉调参台的独立版:一整页 HTML/CSS,参数集中在脚本开头的 CONFIG。
复制代码
代码跟着右侧参数走:你调的每个值都已经写进代码
<div class="scene" id="scene">
<div class="sky"></div>
<div class="sun" id="sun"></div>
<div class="horizon" id="hzline"></div>
<div class="ground-fill"></div>
<div class="refl"></div>
<div class="floor" id="floor"></div>
<div class="skyglow"></div>
<div class="scan" id="scan"></div>
<div class="grain"></div>
<div class="vignette"></div>
<div class="content" id="content">
<div class="eyebrow">Background · No.84</div>
<h1 id="heading">网格地平线</h1>
<p class="lede" id="lede">太阳落进网格里,时间开始往前走。</p>
<div class="actions">
<a class="btn btn-solid" href="#start">开始使用</a>
<a class="btn btn-ghost" href="#more">看实现</a>
</div>
</div>
</div>
<div class="credit" id="credit"><a href="https://uibits.cn" target="_blank" rel="noopener"><span class="mk">UI Bits</span><span class="hair"></span><span>uibits.cn</span><span>↗</span></a><span>组件来自 UI Bits 组件库</span></div>
<script>
/* 参数集中在这里,改数字 / 颜色即生效 */
var CONFIG={
sun:210,
sunLine:0,
hz:58,
pink:'#FF2E88',
cyan:'#22E8FF',
grid:64,
speed:7,
scan:0,
mouse:true,
content:true,
credit:true,
heading:'网格地平线',
lede:'太阳落进网格里,时间开始往前走。'
};
var S=Object.assign({},CONFIG);
var el=function(id){return document.getElementById(id)};
var cs=document.documentElement.style;
var paused=false;
/* 指针:整个场景做极轻的转头,太阳反向位移一点,做出前后层次 */
var tmx=innerWidth*.5,tmy=innerHeight*.5,mx=tmx,my=tmy,scene=el('scene'),sun=el('sun');
window.addEventListener('mousemove',function(e){tmx=e.clientX;tmy=e.clientY});
window.addEventListener('mouseleave',function(){tmx=innerWidth*.5;tmy=innerHeight*.5});
function follow(){
mx+=(tmx-mx)*.05; my+=(tmy-my)*.05;
if(S.mouse){
var px=(mx/innerWidth-.5)*2, py=(my/innerHeight-.5)*2;
scene.style.transform='perspective(1600px) rotateY('+(px*3.4).toFixed(2)+'deg) rotateX('+(-py*2.2).toFixed(2)+'deg) scale(1.1)';
sun.style.transform='translate(-50%,-50%) translate3d('+(px*-34).toFixed(1)+'px,'+(py*-20).toFixed(1)+'px,0)';
}
requestAnimationFrame(follow);
}
follow();
function apply(){
cs.setProperty('--sun',S.sun+'px');
cs.setProperty('--hz',S.hz);
cs.setProperty('--pink',S.pink);
cs.setProperty('--cyan',S.cyan);
var h=String(S.cyan).replace('#','');
if(h.length===3)h=h[0]+h[0]+h[1]+h[1]+h[2]+h[2];
var ci=parseInt(h,16);
if(!isNaN(ci))cs.setProperty('--cyan-rgb',((ci>>16)&255)+','+((ci>>8)&255)+','+(ci&255));
cs.setProperty('--gx',S.grid+'px');
cs.setProperty('--gy',Math.round(S.grid*.68)+'px');
cs.setProperty('--sp',S.speed);
cs.setProperty('--sunLine',(+S.sunLine)+'px');
sun.classList.toggle('noSunLine',+S.sunLine===0);
cs.setProperty('--scan-a',(+S.scan/100*.62).toFixed(3));
el('content').style.display=S.content?'flex':'none';
el('credit').style.display=S.credit?'flex':'none';
el('heading').textContent=S.heading;
el('lede').textContent=S.lede;
}
apply();
if(matchMedia('(prefers-reduced-motion:reduce)').matches)document.body.classList.add('paused');
</script>相似组件
按标签重合度推荐,不是运营手配的榜单。





