Skip to content

Commit 068be22

Browse files
committed
Add height animation
1 parent 27c976f commit 068be22

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

public/css/index.css

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,24 +370,23 @@ input {
370370
}
371371

372372
/*权重需要比 .header-nav 大*/
373-
nav.show {
374-
max-height: 450px;
375-
/* 与正常情况下产生冲突,这里设置 auto */
373+
nav.header-nav.show {
376374
height: auto;
375+
height: calc-size(auto, size);
377376
}
378377

379378
.header-nav {
379+
width: 100%;
380+
height: 0;
380381
display: flex;
381382
flex-direction: column;
382383
position: fixed;
383384
background-color: var(--header-bg);
384385
backdrop-filter: blur(1rem);
385386
-webkit-backdrop-filter: blur(1rem);
386387
inset-block-start: var(--header-height);
387-
width: 100%;
388-
max-height: 0;
389388
overflow: hidden;
390-
transition: max-height 0.5s ease;
389+
transition: height 0.5s ease;
391390
}
392391
}
393392

src/posts/TyepScript_tricky.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ summary: tsconfig.json 配置技巧
2626
}
2727
```
2828

29-
- 此时编译后的文件会分别到 `dist/src1``dist/src2` 目录下。但是如果 `src1`
30-
变化了,`src2` 同时也会再次被编译,这时候我们需要做一些缓存设置
29+
- 此时编译后的文件会分别到 `dist/src1``dist/src2` 目录下。但是如果 `src1` 变化了,`src2` 同时也会再次被编译,这时候我们需要做一些缓存设置
3130

3231
1.`src1``src2` 目录下分别创建 `tsconfig.json` 文件,其中需要添加
3332
`composite:true` 这样的配置

src/posts/css_animation.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: 动画效果
3+
date: 2024-12-30 08:30:03
4+
categories: CSS
5+
tags:
6+
- CSS
7+
summary: 用于收集一些常见的 CSS 动画效果
8+
---
9+
10+
## height 动画效果
11+
12+
众所周知,在之前的 CSS 中,例如 height 属性是不能直接进行动画效果的,需要使用 max-height 配合 transition 或者 animation 来实现该效果。
13+
14+
现在可以使用以下两个属性来实现 height 的动画效果:
15+
16+
1. `calc-size(<calc-size-basis>, <calc-sum>)`: <https://developer.mozilla.org/en-US/docs/Web/CSS/calc-size>,该函数可以接受两个属性,其中第一个属性是初始值,第二个属性是 CSS 数学函数中可计算的值,例如 `height: calc-size(auto, size + 100px);`。(该属性仅针对尺寸属性有效果)
17+
2. `interpolate-size`: <https://developer.mozilla.org/en-US/docs/Web/CSS/interpolate-size>,该属性用于在 [`<length-percentage>`](https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage)[固有尺寸](https://developer.mozilla.org/en-US/docs/Glossary/Intrinsic_Size)之间使用 animation 和 transition 效果。接受两个关键字,一个是 `allow-keywords` 该属性接受某个[插值](https://developer.mozilla.org/zh-CN/docs/Glossary/Interpolation),另一个是 `numeric-only`,该属性为**默认值**不接受插值。
18+
19+
参见:<https://developer.chrome.com/docs/css-ui/animate-to-height-auto>[`<calc-sum>`]((https://developer.mozilla.org/en-US/docs/Web/CSS/calc-sum))

src/util/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export function startServer(
120120
try {
121121
Deno.serve({
122122
port,
123+
hostname: 'localhost',
123124
onListen({ hostname, port }) {
124125
console.log(`Server started at http://${hostname}:${port}`)
125126
},

0 commit comments

Comments
 (0)