2017-08-12 66 views
-2

我想製作動畫,但並不流暢。當我刪除顯示 - 一切正常。如何處理顯示和順利?更改顯示時不能播放動畫

div { 
 
    display: none; 
 
    opacity: 0; 
 
    width: 50px; 
 
    height: 50px; 
 
    transition: opacity 3s; 
 
    background-color: black; 
 
} 
 

 
input:checked + div { 
 
    display: block; 
 
    opacity: 1; 
 
}
<input type="checkbox"> 
 

 
<div></div>

回答

0

嘗試visibility & position,而不是display

div { 
 
    opacity: 0; 
 
    width: 50px; 
 
    height: 50px; 
 
    transition: all 3s; 
 
    background-color: black; 
 
    visibility: hidden; 
 
    position: absolute; 
 
} 
 

 
input:checked+div { 
 
    visibility: visible; 
 
    position: relative; 
 
    opacity: 1; 
 
}
<input type="checkbox"> 
 

 
<div></div><span>&lt;space&gt;</span>

0

HTML

<input type="checkbox" name="name" id="name" /> 

<div id="animation"> 
    test 
</div> 

JQuery的

$('#animation').hide(); 

$('#trending').click(function(){ 
    $('#animation').fadeToggle(); 
}) 
+0

我需要純粹的CSS – Yuri

+0

根據您的要求。我已經添加了另一個答案。 – user8256287

0

我認爲你需要這個

div {width: 50px; 
 
    height: 50px; 
 
    background-color: black; 
 
    visibility:hidden; 
 
    opacity:0; 
 
    transition:all 0.45s; 
 
} 
 

 
input:checked + div { 
 
opacity: 1; 
 
visibility: visible; 
 
}
<input type="checkbox"> 
 
<div></div>

+0

對不起,但沒有。我不需要改變背景,我需要順利顯示區塊 – Yuri

+0

您可以使用'visibility:hidden;'而不是'display:none;',順便說一下,我已經更新了我的答案,請現在檢查 –

0

HTML

<input type="checkbox" id="toggle"> 
<div class="overlay"> 
    <label for="toggle">Click to deactivate</label> 
</div> 

CSS

label { 
    cursor: pointer; 
} 
.overlay { 
    opacity: 0; 
    transition: opacity ease-in 0.6s; 
} 
#toggle:checked ~ .overlay { 
    opacity: 1; 
}