【发布时间】:2017-10-10 21:17:19
【问题描述】:
我有两个问题:
已经回答了
- 我应该在 jQuery 操作中调用哪个选择器来确保只有“Hello World”移动?虽然我只调用它的 id
$("#output")是对的,但即使是按钮也被应用到 js 动作中。
--
--
已经回答了
- 如何确保 jQuery 中的操作重置?在当前代码中,淡入和淡出按钮只工作一次。我希望他们彼此独立地应用操作,以先到者为准(例如,我可以多次单击淡入,一个接一个)。
$(document).ready(function(){
$("#show-button").click(function(){
$("#output").addClass("fadein-animation");
setTimeout(function(){
$("#output").removeClass("fadein-animation"); }, 2000);
});
$("#hide-button").click(function(){
$("#output").addClass("fadeout-animation");
setTimeout(function(){
$("#output").removeClass("fadeout-animation"); },2000);
});
});
body,
html {
height: 100%;
/*to give body and html 100% height of screen*/
}
.flex-container {
height: 100%;
display: -webkit-flex;
justify-content: center;
align-items: center;
border: 2px solid rgba(0, 0, 0, 0.2);
}
.flex-item {
display: -webkit-flex;
align-self: center;
}
.window {
flex-direction: column;
}
.fadein-animation {
animation-duration: 2s;
animation-name: fadein;
}
@keyframes fadein {
from {
height: 100%;
opacity: 0;
}
/*as suggested by @SilverSurfer*/
.buttons-window{
position: fixed;
margin-top:25px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="window flex-container">
<div id="output">Hello World!</div>
<div class="buttons-window">
<button class="btn btn-primary" id="show-button">Fade In</button>
<button class="btn btn-warning" id="hide-button">Fade Out</button>
</div>
</div>
</body>
【问题讨论】:
-
选择答案后,我找到了一个更好的解决方案,使用
transform: translate();这消除了.buttons-window的类定义的需要
标签: javascript jquery html