javascript - transition height auto 過渡動畫
問題描述
1.為什么收縮時,沒有動畫效果?
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)'>開關</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:因為我們所能看到的過渡動畫,其實是height值的變化過程,而你在hover屬性中,并沒有給height賦予明確的值,因此在移出鼠標之后,瀏覽器其實并不知道該從哪個值變化到初始值,于是就直接返回到初始值,所以沒有過渡效果
回答2:原因如1樓所說??梢栽O置height:100%;。
回答3:.container:hover { height: 100%; // 這個要明確值 max-height: 100%; bottom: 0px;}
相關文章:
1. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?2. java - HashSet<int> 為何有錯誤?3. 數據庫無法進入4. java - StringBuffer轉成String,可以不同過tostring,而是通過+“”的方式轉換嗎?5. angular.js - angularjs如何傳遞id給另一個視圖 根據id獲取json數據?6. mysql - 記得以前在哪里看過一個估算時間的網站7. 使用text-shadow可以給圖片加陰影嗎?8. boot2docker無法啟動9. 請問一下各位老鳥 我一直在學習獨孤九賤 現在是在tp5 今天發現 這個系列視頻沒有實戰10. python - linux怎么在每天的凌晨2點執行一次這個log.py文件
