<div class="highlightable content">
<h1>突出光标设计<br>提升用户体验</h1>
<h2>当鼠标悬停到不同尺寸的字体上时</h2>
<h3>光标尺寸也会变化</h3>
<p>试试更小的文字,这段文字并没有任何特定的含义,它只是为了模拟真实的文字内容,以展示字体、版式和布局等设计元素。占位文本可以帮助设计师专注于页面的整体布局和视觉效果,而不会被实际内容的含义所干扰。</p>
<h4>Cool!</h4>
</div>
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ... </head>
<body>
</body>
html {
font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
line-height: 1.5rem;
font-size: 1.3em;
}
*, *::before, *::after { box-sizing:border-box }
:root {
--cursor-height: 0px;
}
body {
margin:0;
display:grid;
place-items:center;
min-height:100vh;
line-height: 1;
background-color: papayawhip;
color: rgb( 0 0 0 / 0.9);
}
*::selection {
background: rgb( 255 255 0 / 0.6);
background-blend-mode: overlay;
}
.content {
max-width:560px;
text-align:center;
}
.highlightable {
--show-cursor: none;
cursor:none;
&:hover {
--show-cursor: block;
}
&::after {
--cursor-width: max( 5px, calc( var(--cursor-height) * .4) );
display: var(--show-cursor);
content:"";
pointer-events:none;
background:transparent;
border: 2px solid rgb( 0 0 0 / 0.75);
border-radius: calc( var(--cursor-width) / 2 );
translate: -50% -50%;
position:absolute;
top: var(--mouse-y, 0);
left: var(--mouse-x, 0);
width: var(--cursor-width);
height: var(--cursor-height);
cursor:none;
transition: height 0.3s cubic-bezier(0.095, 1.090, 0.605, 1.235),
width 0.3s cubic-bezier(0.095, 1.090, 0.605, 1.235);
backdrop-filter: blur(3px);
-webkit-backdrop-filter: blur(3px);
}
}
h1, h2, h3, h4, p {
margin-block: 50px;
}
h1 {
font-size: 3rem;
}
h2 {
font-size: 2rem;
text-transform:uppercase;
}
h3 {
font-size: 5rem;
}
h4 {
font-size: 15vw;
}
document.body.addEventListener( 'mousemove', (e) => {
document.documentElement.style.setProperty('--mouse-x', `${e.pageX}px`);
document.documentElement.style.setProperty('--mouse-y', `${e.pageY}px`);
});
document.body.querySelectorAll('.highlightable > *').forEach( el => {
el.addEventListener( 'mouseenter', () => {
const fs = getComputedStyle(el).getPropertyValue('font-size');
const lh = getComputedStyle(el).getPropertyValue('line-height');
document.documentElement.style.setProperty('--cursor-height', `calc( ${fs} + (${lh}/4) )` );
})
});