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)'>開關(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)槲覀兯芸吹降倪^渡動畫,其實(shí)是height值的變化過程,而你在hover屬性中,并沒有給height賦予明確的值,因此在移出鼠標(biāo)之后,瀏覽器其實(shí)并不知道該從哪個值變化到初始值,于是就直接返回到初始值,所以沒有過渡效果
回答2:原因如1樓所說。可以設(shè)置height:100%;。
回答3:.container:hover { height: 100%; // 這個要明確值 max-height: 100%; bottom: 0px;}
相關(guān)文章:
1. python - django 里自定義的 login 方法,如何使用 login_required()2. python如何不改動文件的情況下修改文件的 修改日期3. angular.js - Angular路由和express路由的組合使用問題4. angular.js - angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性5. mysql優(yōu)化 - mysql count(id)查詢速度如何優(yōu)化?6. 主從備份 - 跪求mysql 高可用主從方案7. css3 - [CSS] 動畫效果 3D翻轉(zhuǎn)bug8. angular.js - 不適用其他構(gòu)建工具,怎么搭建angular1項(xiàng)目9. mysql主從 - 請教下mysql 主動-被動模式的雙主配置 和 主從配置在應(yīng)用上有什么區(qū)別?10. node.js - node_moduls太多了
![css3 - [CSS] 動畫效果 3D翻轉(zhuǎn)bug](http://www.cgvv.com.cn/attached/image/news/202304/110831f073.png)