书架我写的三个系列
开屏笔记12 篇动效小记8 篇AI 日志20 篇
3D 书本侧转
3D book
文章像一本立体的书,鼠标放上去,书转过来露出书页
常见大白话搜法:文章做成一本本立体的书、鼠标放上去,书转过来露出书页的厚度、像书架上的书,悬停时侧过来、立体书封面
- 适用位置
- 卡片列表
- 气质感觉
- 俏皮、高级
- 触发方式
- 悬停
- 适合网站
- 博客、个人网站、作品集
实现原理与无障碍底线
书由封面、书页的侧面和封底三层叠成(封面在前、封底在后、书页立在右边),平时正对着人;鼠标停上去时整本书绕竖轴转过来一个角度,露出书页的厚度,离开时转回去。只用 CSS(3D 变换和过渡)。
适用场景:文章合集、书单、系列教程这类"一本一本"的东西:比平平的卡片多一点实物感。一排放三五本,太多会挤
减少动态(prefers-reduced-motion):照样转过来,但不做过渡,直接到位
移动端与触屏:手机上没有悬停:手指按住时转过来(:active),松开转回去,点一下照常打开;iOS Safari 要页面上有触摸监听才认 :active
关键可调参数
| 参数 | 键名 | 默认值 | 建议范围 | 说明 |
|---|---|---|---|---|
| 转过来的角度 | angle | 30° | — | — |
| 时长 | duration | 700ms | — | — |
| 缓动 | easing | cubic-bezier(0.22, 1, 0.36, 1) | — | — |
可直接复制给 AI(Cursor / Claude / v0)的提示词
请在我的项目里给卡片列表加上「3D 书本侧转」(3D book)效果:书由封面、书页的侧面和封底三层叠成(封面在前、封底在后、书页立在右边),平时正对着人;鼠标停上去时整本书绕竖轴转过来一个角度,露出书页的厚度,离开时转回去。只用 CSS(3D 变换和过渡)。
参数:转过来的角度 30°,时长 700ms,缓动 cubic-bezier(0.22, 1, 0.36, 1)。
要求:保留原有的内容和布局;系统开启"减少动态"时直接显示最终状态;脚本出错或没有执行时内容仍然可见。
参考:https://donglang.linter.top/effects/book-3d.md(原理、参数和参考代码)原生无依赖参考代码
CSS
/* 3D 书本侧转(3D book)· 只用 CSS,不需要脚本。
思路来自 x/UI 的 Book(许可没查到,只学原理,没有用它的代码)。
一本书由三层叠成:封面(.book-cover)往前挪半本书的厚度,封底(.book-back)往后挪半本,书页的侧面(.book-pages)转 90 度立在右边。
平时正对着人,看起来就是一张封面;鼠标停上去、键盘选中时,整本书绕竖轴转过来 --book-angle,露出右边书页的厚度;离开时转回去。
转的是里面那一层(.book-body),外面的链接(.book)不动:转的时候鼠标不会滑出去,不会一转一停。
- 书的大小、厚度按自己的网站改(--book-width、--book-depth),封面、封底的颜色写在下面。封面超出的部分会被裁掉(overflow: hidden),书名长的话把字改小或者让它折行。
- 想让某一本一直转着(比如"正在读"的那本),加 class="is-open"。
- 悬停只在能悬停的设备上生效;手机上手指按住时转过来(:active)。iOS Safari 要页面上有触摸监听才认 :active:
页面里别处已经有就不用管,没有的话给 body 加 ontouchstart(空的就行)。
- 不认 3D 变换的浏览器上,书就是一张平的封面。
- 开启"减少动态"时:照样转过来,不做过渡。 */
.book {
--book-angle: 30deg;
--book-duration: 700ms;
--book-easing: cubic-bezier(0.22, 1, 0.36, 1);
--book-width: 140px;
--book-depth: 22px;
display: inline-block;
perspective: 900px;
color: inherit;
text-decoration: none;
}
.book-body {
position: relative;
display: block;
width: var(--book-width);
aspect-ratio: 3 / 4;
transform-style: preserve-3d;
transition: rotate var(--book-duration) var(--book-easing);
}
.book-cover,
.book-back { position: absolute; inset: 0; border-radius: 2px 8px 8px 2px; }
.book-cover {
display: flex;
flex-direction: column;
justify-content: flex-end;
padding: 14px 14px 14px 18px;
overflow: hidden;
background: #2f3a33;
color: #fff;
translate: 0 0 calc(var(--book-depth) / 2);
}
/* 书脊那一侧的压痕和高光 */
.book-cover::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 8%; background: linear-gradient(90deg, rgb(0 0 0 / 0.18), rgb(255 255 255 / 0.18) 55%, rgb(0 0 0 / 0.1)); }
.book-back { background: #232b26; translate: 0 0 calc(var(--book-depth) / -2); box-shadow: 6px 8px 22px rgb(0 0 0 / 0.25); }
.book-pages {
position: absolute;
top: 3px;
bottom: 3px;
right: calc(var(--book-depth) / -2);
width: var(--book-depth);
background: repeating-linear-gradient(90deg, #fff 0 2px, #e9e9e6 2px 3px);
rotate: y 90deg;
}
@media (hover: hover) {
.book:hover .book-body { rotate: y calc(-1 * var(--book-angle)); }
}
@media (hover: none) {
.book:active .book-body { rotate: y calc(-1 * var(--book-angle)); }
}
.book:focus-visible .book-body,
.book.is-open .book-body { rotate: y calc(-1 * var(--book-angle)); }
@media (prefers-reduced-motion: reduce) {
.book-body { transition: none; }
}HTML
<!-- 3D 书本侧转:每篇文章(每个合集)一本书,书是链接;封面里写标题,书页和封底是空的装饰层(不给读屏读)。不需要脚本 -->
<div class="shelf">
<a class="book" href="/series/opening">
<span class="book-body">
<span class="book-cover"><b>开屏笔记</b><small>12 篇</small></span>
<span class="book-pages" aria-hidden="true"></span>
<span class="book-back" aria-hidden="true"></span>
</span>
</a>
<a class="book" href="/series/motion">
<span class="book-body">
<span class="book-cover"><b>动效小记</b><small>8 篇</small></span>
<span class="book-pages" aria-hidden="true"></span>
<span class="book-back" aria-hidden="true"></span>
</span>
</a>
</div>