javascript - transition height auto 過渡動(dòng)畫
問題描述
1.為什么收縮時(shí),沒有動(dòng)畫效果?
2.代碼
<!DOCTYPE html><html lang='en'><head> <title></title> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1'> <style>* { transition: all .6s;}.container { position: fixed; top: 0; left: 0; right: 0; height: 100px; max-height: 100px; width: 100px; margin: 5px auto; background: RGBA(0, 43, 54, 0.80); overflow: hidden; text-align: center;}.container:hover { height: auto; max-height: 100%; bottom: 0px;} </style></head><body> <p class='sketch'><p class='container'> <!--<a href='javascript:void(0)'>開關(guān)</a>--></p> </p> <!--<script>const classList = document.querySelector(’.container’).classList;document.querySelector(’#switch’).addEventListener(’click’, function (e) { if (classList.contains(’expand’)) {document.querySelector(’.container’).classList.remove(’expand’); } else {document.querySelector(’.container’).classList.add(’expand’); }}); </script>--></body></html>
3.在線Demo(己解決)
問題解答
回答1:因?yàn)槲覀兯芸吹降倪^渡動(dòng)畫,其實(shí)是height值的變化過程,而你在hover屬性中,并沒有給height賦予明確的值,因此在移出鼠標(biāo)之后,瀏覽器其實(shí)并不知道該從哪個(gè)值變化到初始值,于是就直接返回到初始值,所以沒有過渡效果
回答2:原因如1樓所說。可以設(shè)置height:100%;。
回答3:.container:hover { height: 100%; // 這個(gè)要明確值 max-height: 100%; bottom: 0px;}
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. html5 - javascript讀取自定義屬性的值,有的能夠取到,有的取不到怎么回事??3. html - Python2 BeautifulSoup 提取網(wǎng)頁中的表格數(shù)據(jù)及連接4. python - PyCharm里的一個(gè)文件不小心忽略了wx包5. android - VideoView與百度Map沖突6. python - (2006, ’MySQL server has gone away’)7. 小白學(xué)python的問題 關(guān)于%d和%s的區(qū)別8. python - 使用eclipse運(yùn)行django代碼,修改了views.py這個(gè)文件,但是瀏覽器顯示的還是原有沒修改的結(jié)果,怎么處理?9. django - pycharm 如何配置 python3 的開發(fā)環(huán)境?10. win10 Apache24+PHP8.0,Apache不能正常加載php.ini。
