JQuery/CSS:静态位置动画
JQuery/CSS: Animate static position
我正在尝试从一种表单字段类型平滑过渡到另一种。但是,如果我插入另一个<input>
元素,则不会为下一个元素的静态位置设置动画。
$("#switchlogin").click(function() {
//Create the label element
var emaillabel = $("<label>").text("Email").attr("for", "email");
//Create the input element
var emailinput = $('<input type="text">').attr({
id: "email",
name: "email"
});
//Create the label element
var pwdlabel = $("<label>").text("Repeat Password").attr("for", "password-wh");
//Create the input element
var pwdinput = $('<input type="password">').attr({
id: "password-wh",
name: "password-wh"
});
$("#username-field").after(emaillabel);
emaillabel.after(emailinput);
$("#password-field").after(pwdlabel);
pwdlabel.after(pwdinput);
});
input {
border: solid #e3e3e3 1pt;
display: block;
margin-bottom: 1em;
font-size: 14pt;
opacity: 0;
animation: fadeIn .3s forwards;
}
label {
opacity: 0;
animation: fadeIn .3s forwards;
}
@keyframes fadeIn {
to {
opacity: 1;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="<?php the_permalink(); ?>" id="login" method="post">
<div id="username-field">
<label for="username">Username</label>
<input type="text" id="username" name="username">
</div>
<div id="password-field">
<label for="password">Password</label>
<input type="password" id="password" name="password">
</div>
<div id="buttons-field">
<button type="submit">Login</button>
<a href="#" id="switchlogin">Register</a>
</div>
</form>
https://jsfiddle.net/fpvctpjs/2/
所以我想要的是,当按下寄存器链接时,password-field
会平滑地向下移动,为新元素腾出位置。
我尝试了几种方法,比如添加margin-top
、position:absolute
或position:relative
,但不知何故,我无法使其发挥作用。
感谢您的帮助,
marsman
您的密码字段无法顺利设置动画,因为它的移动是附加其他字段的结果。
最好是让其他字段始终存在,但隐藏在高度为0的div内部--然后,当您单击重置按钮时,将动画设置为该div所需的高度,并淡入子输入。
相关文章:
- jquery:将动画绑定到滚动条位置的更好方法
- Famo.us Js-将实体(粒子)设置到位置的动画
- 在位置更改时为阵列项目制作动画
- 仅为背景位置X轴制作动画
- 如何使用jQuery对固定元素的位置进行动画处理
- 是否可以设置柔盒插入、移除和项目位置的动画
- 如何获取SVG动画的当前时间/位置
- 在变换的绝对位置发生变化时制作动画's参数
- 如何使用CSS-webkit动画制作位置动画
- 视差'背景图像/位置/附件'jQuery的动画很不稳定
- 创建从一个位置到另一个位置的路径动画
- 使用gsap制作背景位置动画
- 悬停时的背景位置动画
- 跨浏览器背景Y位置动画
- JQuery/CSS:静态位置动画
- 使用svg.js设置位置动画的正确方法是什么
- 将画布形状从任何位置动画到中心
- 位置动画在IE上运行缓慢
- Firefox和IE中的背景位置动画问题
- jquery在Chrome和Opera中的位置动画问题