jquery - 按下按钮时动画跨度
问题描述
我正在尝试创建一个网络投资组合,我希望登录页面上的两个按钮在按下其中一个按钮为文本腾出空间时向上移动。由于某种原因,按钮不会随着我当前的设置移动。有任何想法吗?这是我的相关代码:
javascript
$(document).ready(function(){
$('button').click(function(){
$('#Name').addClass("animated fadeOutUp")
$('#options').addClass("slideUp")})})
html
<div class = "content animated fadeInUp">
<h1 id="Name">TOM KAIZER</h1>
<p></p>
<span id = "options">
<button type = "button" class = "button grow"class = 'resume' style = "text-decoration: none; color: black;">Resume</button>
<button type = "button" class = "button grow contact" style = "text-decoration: none; color: black;">Contact Me</button>
</span>
</div>
CSS
@keyframes slideUp{
from{
opacity: 0;
}
to{
opacity:1;
transform: translateY(-20px);
}
};
@-webkit-keyframes slideUp{
from { top: 0; left: 0; }
to { top: 100px; left: 100px; }
};
.slideUp{
animation-name:slideUp;
-webkit-animation-name:slideUp;
animation-duration: 3s;
-webkit-animation-duration: 3s;
animation-fill-mode: forwards
}
解决方案
这是一个位置问题。只需将@keyframes 放在 .slideUp 之后,它就会起作用。要使按钮真正移动,您需要设置 CSS 显示属性。
.slideUp{
position: absolute;
animation-name:slideUp;
-webkit-animation-name:slideUp;
animation-duration: 3s;
-webkit-animation-duration: 3s;
animation-fill-mode: forwards;
}
@keyframes slideUp{
from{
opacity: 0;
}
to{
opacity:1;
transform: translateY(-20px);
}
};
@-webkit-keyframes slideUp{
from { top: 0; left: 0; }
to { top: 100px; left: 100px; }
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class = "content animated fadeInUp">
<h1 id="Name">TOM KAIZER</h1>
<p></p>
<span id = "options">
<button type = "button" class = "button grow"class = 'resume' style = "text-decoration: none; color: black;">Resume</button>
<button type = "button" class = "button grow contact" style = "text-decoration: none; color: black;">Contact Me</button>
</span>
</div>
<script>
$(document).ready(function(){
$('button').click(function(e){
$('#Name').addClass("animated fadeOutUp");
$('#options').addClass("slideUp");
});
});
</script>
推荐阅读
- r - 在单击左侧边栏菜单项时激活/停用闪亮仪表板右侧栏中的选项卡
- angular - 如何以角度访问另一个函数中的一个函数中分配的全局变量
- python - Tkinter Checkbuttons不改变变量值
- typescript - Plugin<{}> 中的花括号是做什么用的?
- ios - 如何在 ios swift5 中编码 firebase 时间戳?
- java - 模拟静态块(错误:java.lang.IllegalStateException)
- java - 为什么当我尝试解析当前 LocalDateTime 时出现解析异常
- haskell - 使用haskell项目euler 25的慢速解决方案
- javascript - 在 TestCafé 测试中注入的 injectScripts 中的脚本在哪里?
- r - 使用 cor.test 和 rcorr 的不同 P 值