css - 带反应的条纹文档样式sidenav
问题描述
有没有人知道如何在条纹文档页面https://stripe.com/docs上实现侧导航 侧导航具有嵌套元素。我想知道如何单击主页上的“付款”打开付款侧导航及其嵌套列表并重定向到付款页面。我知道这没有意义,但是如果您单击文档页面并尝试一下,您可能会理解我想要实现的目标。
解决方案
You can achieve similar behavior with CSS height transition. They appears to be pretty smooth on desktop (60fps is achievable but not through full transition period). If you need more control (for example close other navigation 'ul's when other is opened) you can remove checkbox elements and change label elements to "h2". Then set "onclick" listener on "h2" elements in JS code that will add class (with styles from "input:checked ~ ul") to selected "ul".
:root {
--liHeight: 1em
}
label {
cursor: pointer
}
ul {
opacity: 0;
height: 0px;
overflow: hidden;
transition: 0.3s;
}
ul li {
height: var(--liHeight);
}
input {
position: absolute;
opacity: 0;
}
input:checked ~ ul {
opacity: 1;
position: initial;
height: calc(7 * var(--liHeight));
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="item">
<label for="item1">
Item 1
</label>
<input id="item1" type="checkbox"/>
<ul>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
</div>
<div class="item">
<label for="item2">
Item 2
</label>
<input id="item2" type="checkbox"/>
<ul>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
</div>
<div class="item">
<label for="item3">
Item 3
</label>
<input id="item3" type="checkbox"/>
<ul>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
</div>
</body>
</html>
Another solution is to write JS animation, for example using "window.requestAnimationFrame" API, to animate height of "ul" element. (I think that this is what exacly is happening on stripe.com)
推荐阅读
- java - 如何在改造请求的界面中设置参数
- assembly - 为什么 cmp 指令中的参数顺序很重要?
- c# - 外键 ID 转换(C# 到 SQL Server)
- angular - 分页器,排序和过滤器不适用于角度材料项目
- mongodb - 获取计数和文档详细信息
- python - 如何在 Pytorch1.1 & DistributedDataParallel() 中计算米?
- r - 如何在 R 中创建密度图矩阵
- angularjs - 如何使用 ng-repeat 功能显示 2 个实心量规?
- r - 是否有 R 函数对列变量进行排序?
- rest - REST 微服务 api 读取后如何将属性文件保存在某个本地内存中