javascript - 仅使用 css 和 vanilla js 在没有插件的情况下向下滚动时从顶部显示一个按钮
问题描述
我想要一个按钮从隐藏到顶部平滑出现(动画):10px 右:10px。
我不能使用任何库,只能使用 css 和 vanilla js。
我目前的解决方案如下:`
@keyframes example {
from { top: -10px }
to { top: 10px }
}
.navButton {
position: fixed;
top: 10px;
right: 10px;
z-index: 2000;
animation-name: example;
animation-duration: 3s;
animation-iteration-count: 1;
}
`
该按钮最初在那里,然后当我刷新时,它从顶部出现,但严重滞后。
解决方案
你的 CSS 对我来说很好。你使用的是什么浏览器?
为了让它更流畅,你可以像我在这里一样使用“从位置”和持续时间(在 Edge、Firefox 和 Chrome 中测试):
@keyframes example {
from { top: -100px }
to { top: 10px }
}
.navButton {
position: fixed;
top: 10px;
right: 10px;
z-index: 2000;
animation-name: example;
animation-duration: 1s;
animation-iteration-count: 1;
}
<button class="navButton">test button</button>
推荐阅读
- php - 启用 Mcrypt 的 PHP 7.2 上的 Laravel 4.2 仍然显示“需要 Mcrypt PHP 扩展”。在浏览器上
- javascript - 从 Vue.js 中的 Route 获取上一个 URL
- postgresql - 使用 PostgreSQL,如何表达两个时间范围在其他条件成立的情况下不重叠的表约束?
- amazon-dynamodb - 在 AppSync 中使用多个 begin_with 子句查询 DynamoDB
- python - 创建一个 numpy 数组,其中包含 .npz 输入文件的数组列表
- android - 如何将两种信息写入nfc标签并让阅读器同时读取它们?
- javascript - React-Router 路由到类组件
- json - 如何从响应正文中获取令牌值?
- google-cloud-dataflow - 使用状态或计时器时避免重新洗牌?
- python-3.x - defaultdict 的默认值是一个带参数的 lambda 会产生错误