在淡入淡出框之前,如何让柔性框不成为页面的一部分?我曾经用'display:0;'做到这一点然后使用jquery .fadeIn()。但是现在如果我将显示设置为0,当我淡入时,我当然会失去盒子的柔韧性。如果我使用jquery将display设置为flex,那么它只会出现,而不是淡入。
<div class="" id="popupContainer">
<div class="flex-item-popup" id="popup">
<div class="close"><i class="fa fa-2x fa-times-circle"></i></div>
<h2></h2>
<div class='text'></div>
<div class="videos"></div>
<div class="flex-container images"></div>
</div>
#popupContainer {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display:flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-content: flex-start;
align-items: center;
z-index: 15;
}
jquery的:
$(document).ready(function() {
//???
});
答案 0 :(得分:84)
看起来有点奇怪,但你可以做的是在css中,将它设置为display: none
。然后诀窍是在你的jquery中将display
设置为flex
,然后再次隐藏它,然后fadeIn
:
CSS :
#popupContainer {
/* ... */
display:none;
flex-direction: row;
flex-wrap: wrap;
/* ... */
}
JS :
$("#popupContainer")
.css("display", "flex")
.hide()
.fadeIn();
这是有效的,因为fadeIn()
会将项目设置回其先前的非隐藏display
值。因此,设置flex
并重新隐藏它将设置此&#34;默认&#34;因为它要回到。
http://jsfiddle.net/z2kxyjcq/1/
$("#popupContainer")
.css("display", "flex")
.hide()
.fadeIn(2000);
&#13;
#popupContainer {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display:none;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-content: flex-start;
align-items: center;
z-index: 15;
background-color: red;
}
#popupContainer *{
border: 1px solid blue;
background-color: white;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="" id="popupContainer">
<div class="flex-item-popup" id="popup">
<div class="close"><i class="fa fa-2x fa-times-circle">1</i></div>
<h2>2</h2>
<div class='text'>a</div>
<div class="videos">b</div>
<div class="flex-container images">c</div>
</div>
&#13;
答案 1 :(得分:5)
您可以将不透明度设置为0并设置动画:
$('#popupContainer').animate({
opacity: 1
}, 'fast');
答案 2 :(得分:1)
var flex = $('#flex');
console.log(flex.css('display'));
flex.hide();
flex.velocity('fadeIn', {duration: 100, display: 'flex'});
setTimeout(function(){
console.log(flex.css('display'));
}, 100);
&#13;
#flex{
display: 'flex'
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.5.0/velocity.min.js"></script>
<div id="flex"></div>
&#13;
答案 3 :(得分:1)
最简单,最干净的方式(如果你可以编辑DOM)是包装元素,并在内部有flex的div时淡化包装
<div class="popup" id="popupContainer">
<div class="popup__flexbox">
<div class="popup__flex-item" id="popup">
<div class="popup__close">
<i class="fa fa-2x fa-times-circle"></i>
</div>
<h2></h2>
<div class='popup__text'></div>
<div class="popup__videos"></div>
<div class="popup__images"></div>
</div>
</div>
的CSS:
.popup {
display: none;
}
.popup__flexbox {
display: flex;
}
JS:
$("#popupContainer").fadeIn();