javascript - 动画固定元素
问题描述
我正在尝试在我的表单中添加一个上滑动画,但到目前为止我还没有运气。
基本上点击一个按钮,表单就会出现,表单固定在屏幕的中心,向用户显示内容。然而,在过去的几天里,我一直在尝试添加一个非常简单的幻灯片动画。
动画应该需要 1 秒,并且表单应该向上滑动到设备可用的最大高度,但正如我之前提到的,目前还没有运气。
我确实在表单上尝试了一个简单的不透明动画,但它没有被修复并且它有效,这表明固定元素导致了问题,但我不确定这是否是问题的全部范围。
下面我将提供我用于表单的标记,包括 HTML(EJS 模板)和 CSS(SCSS)。
<!-- HTML Markup -->
<div id="modal-form">
<span aria-hidden="true" id="close"><i class="fas fa-times"></i> </span>
<div class="modal-content" role="document">
<div class="modal-header">
<h3> <%= campground.name %><span></span> Enquiry Form</h3>
</div>
<div class="modal-body">
<% include ../partials/enquiry-form %>
</div>
</div>
</div>
//Styling for the form
#modal-form {
@include position(fixed,0,0,0,0); //position, left, right, bottom, top
background-color: $white;
z-index: 2;
visibility: hidden;
@include flex(column, center, center); //Flex by default, flex-direction, justify-content, align-items
width: 100%;
//Close button
#close {
@include position(absolute,0,null,null,0); //position, left, right, bottom, top
@include border-radius(100%);
margin: 10px;
padding: 3px 8px;
i {
font-size: 2rem;
&:hover {
cursor: pointer;
}
}
}
.modal-content {
position: relative;
@include flex(column, null, null); //Flex by default, flex-directio, justify-content, align-items
width: 80vw;
margin-top: 50px;
.modal-header {
@include flex(column, center, center); //Flex by default, flex-direction, justify-content, align-item
}
h3 {
font-weight: $font-weight-normal;
font-size: $h3-size;
}
.modal-body {
@include flex(null, center, null); //Flex by default, flex-direction, justify-content, align-items
}
}
}
我希望有人能帮我解决这个简单的问题,这是我第一次尝试做动画,我觉得它适合这种形式。它看起来相对但显然不适合我的场景。
干杯,
亚历克斯
解决方案
它的要点是,不是使用转换,而是在 CSS 中将元素的起点设置为底部:0,并且动画关键帧应该使用固定元素的位置。所以它可以从底部:100% 到底部:0,反之亦然,以便上下滑动。
推荐阅读
- python - subprocess.run 输出为空(python 3.8)
- c++ - 我可以为 GCC 和 Clang 中的单个函数启用严格的浮点行为吗?
- python - 列表框中的 Python os.system 输出值“0”
- java - 如何实现 Hashmap 的底层键集以使 add 方法失败?
- python - 如何在 Python 中一次捕获多个异常并处理单个异常?
- amazon-web-services - Elastic Beanstalk 和 RDS 实例的日志记录
- vb.net - 添加 VisualBasic.dll 文件;参考标签不显示
- java - 使用命令 'make' 出错: process_begin: CreateProcess(NULL
- php - 如何将值传递给 add_action() 闭包?
- angular - Angular 清理 html 但保留内联样式