喜歡標題說。我有這樣的代碼:https://jsfiddle.net/fwo9ym1o/css轉換不透明不工作,其中元素有顯示:none然後更改爲顯示:塊
//javascript
var container = document.querySelector("#container");
container.style.display = "block";
//this is not working
//container.style.opacity = 1;
//this is working
setTimeout(function() {
container.style.opacity = 1;
}, 0);
/css
.container {
height: 200px;
width: 200px;
background-color: salmon;
display: none;
border-radius: 5px;
opacity: 0;
transition: opacity 2s ease-in-out;
}
//html
<div id="container" class="container"></div>
所以,我已經改變了container.style.display = "block";
然後應用container.style.opacity = 1;
和過渡沒有發生。
它工作,如果我在一個新的線程中運行的一切。
注意:我無法使用可視性。它必須顯示:無
_「和過渡是不會發生」 _預期的結果是在鉻和Firefox訪問的jsfiddle返回。你在哪個瀏覽器中嘗試過'css','javascript'? – guest271314
它工作,如果我使用setTimout,如果你取消注意它不起作用 –
使用'setTimeout'有什麼問題? – guest271314