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楼所说。可以设置height:100%;。
回答3:.container:hover { height: 100%; // 这个要明确值 max-height: 100%; bottom: 0px;}
相关文章:
1. 一个走错路的23岁傻小子的提问2. angular.js - angularjs 使用鼠标悬停时,标签一直闪3. c++ - win764位环境下,我用GCC为什么指针占8个字节,而long是4个字节?4. html5 - HTML代码中的文字乱码是怎么回事?5. java - 安卓电视盒子取得了root权限但是不能安装第三方应用,请问该怎么办?6. javascript - SuperSlide.js火狐不兼容怎么回事呢7. android - 安卓activity无法填充屏幕8. python 计算两个时间相差的分钟数,超过一天时计算不对9. python - django 里自定义的 login 方法,如何使用 login_required()10. node.js - 函数getByName()中如何使得co执行完后才return
