展示HN:我看到一个很酷的导航展开效果,所以用简单的HTML+CSS做了一个版本。
Show HN: I saw this cool navigation reveal, so I made a simple HTML+CSS version

原始链接: https://github.com/Momciloo/fun-with-clip-path

这是一个简单的代码探索,灵感来自(并借鉴自)https://iventions.com/,在X平台看到。在这个例子中,我尝试实现一个在用户点击按钮时显示的菜单。仅使用HTML+CSS,不使用JS。有两个剪切路径:菜单通过一个从屏幕左上角增长到右下角的圆来显示。我在这里使用的一个有趣的剪切路径计算(clip-path: circle(calc(1.42 * 100vmax) at 0 0);)基于vmax,它是视口宽度或高度中较大的那个。然后乘以1.42,因为1.42是2的平方根,这是视口宽度与高度之比。第二个剪切路径是一个多边形,用于模拟“射线”。多边形现在是硬编码的,但可以使用js计算,以实现尊重导航尺寸的动态尺寸和响应式设计。感谢您的访问。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Show HN: 我看到了一个很酷的导航展开效果,所以我用简单的 HTML+CSS 制作了一个版本 (github.com/momciloo) 10 分,作者 momciloo,2 小时前 | 隐藏 | 过去 | 收藏 | 讨论 导航栏上使用了两个 clip-path: - 第一个 clip-path 是一个圆形(左上角) - 第二个 clip-path 是一个多边形,像光线一样(硬编码,可以改进) Iventions Events https://iventions.com/ 的原始作品使用了 JavaScript,但我发现仅使用 CSS 的方法更有趣。 演示和代码库在这里:https://github.com/Momciloo/fun-with-clip-path 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系方式 搜索:
相关文章

原文

This is a simple code exploration, inspired by (and stollen from) https://iventions.com/, saw it on X here.

CleanShot 2026-02-07 at 18 32 03

In this example, I'm trying to implement a menu that is revealed when the user clicks on a button. With HTML+CSS only. No JS.

There are two clip-paths:

The menu is revealed by a circle that grows from the top-left corner of the screen to the bottom-right corner. A fun clip-path calculation that I used here (clip-path: circle(calc(1.42 * 100vmax) at 0 0);) is based on the vmax, which is the larger of the viewport width or height. Then multiplied it by 1.42, because 1.42 is the square root of 2, which is the ratio of the width to the height of the viewport.

The second clip-path is a polygon that is used to simulate the "ray". The polygon is hardcoded now, but it can be calculated with js, for dynamic dimension that respect the navigation dimensions for responsiveness.

Thanks for stopping by.

联系我们 contact @ memedata.com