js点击弹出div菜单,让它慢慢展开怎样实现呢

qingwadaxia_1 2017-06-27 03:38:42
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{padding:0;margin:0;list-style:none;text-decoration:none;}
#cc{background:#000;height:60px;position:relative;border-bottom: 1px solid #ccc;}
#bb{height: 24px;display: block;padding-top: 18px;width: 8%;position:absolute;right:0;right: 2%;}
#cc span{background:#fff;width:100%;height:4px;display:block;}
#cc span:nth-child(2){margin-top:6px;}
#cc span:nth-child(3){margin-top:6px;}
#aa{background:#000;height:204px;display:none;}
#aa ul li{height:40px;line-height:40px;border-bottom:1px solid #ccc;}
#aa ul li:nth-child(5){border-bottom:none;}
#aa ul li a{color:#fff;display:block;text-indent:2em;}
</style>
</head>
<body>
<div id="cc">
<a id="bb" href="javasrcipt:;">
<span></span>
<span></span>
<span></span>
</a>
</div>
<div id="aa">
<ul>
<li><a href="#">xiaoming</a></li>
<li><a href="#">zhanghong</a></li>
<li><a href="#">guanyuzhang</a></li>
<li><a href="#">lvbugege</a></li>
<li><a href="#">zhaoyunjie</a></li>
</ul>
</div>
<script>
var bb = document.getElementById("bb");
var aa = document.getElementById("aa");
var b1 = true;
bb.onclick=function(){
if (b1)
{
aa.style.display="block";
b1=false;
}else{
aa.style.display="none";
b1=true;
}
}


</script>



</body>
</html>


上面的代码 可以点击弹出显示 但是是直接弹出 显示 没什么过渡效果 想要有那种平滑过渡的效果 慢慢展开和慢慢隐藏
...全文
1004 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
            text-decoration: none;
        }

        #cc {
            background: #000;
            height: 60px;
            position: relative;
            border-bottom: 1px solid #ccc;
        }

        #bb {
            height: 24px;
            display: block;
            padding-top: 18px;
            width: 8%;
            position: absolute;
            right: 0;
            right: 2%;
        }

        #cc span {
            background: #fff;
            width: 100%;
            height: 4px;
            display: block;
        }

            #cc span:nth-child(2) {
                margin-top: 6px;
            }

            #cc span:nth-child(3) {
                margin-top: 6px;
            }

        #aa {
            transition: height 0.3s linear;
            background: #000;
            height: 0;
            overflow:hidden
        }

            #aa ul li {
                height: 40px;
                line-height: 40px;
                border-bottom: 1px solid #ccc;
            }

                #aa ul li:nth-child(5) {
                    border-bottom: none;
                }

                #aa ul li a {
                    color: #fff;
                    display: block;
                    text-indent: 2em;
                }
    </style>
</head>
<body>
    <div id="cc">
        <a id="bb" href="javascript:;">
            <span></span>
            <span></span>
            <span></span>
        </a>
    </div>
    <div id="aa">
        <ul>
            <li><a href="#">xiaoming</a></li>
            <li><a href="#">zhanghong</a></li>
            <li><a href="#">guanyuzhang</a></li>
            <li><a href="#">lvbugege</a></li>
            <li><a href="#">zhaoyunjie</a></li>
        </ul>
    </div>
    <script>
        var bb = document.getElementById("bb");
        var aa = document.getElementById("aa");
        var b1 = true;
        bb.onclick = function () {
            if (b1) {
                aa.style.height='204px'
                b1 = false;
            } else {
                aa.style.height = '0'
                b1 = true;
            }
        }


    </script>



</body>
</html>
___紫菜 2017-06-27
  • 打赏
  • 举报
回复
animate
qingwadaxia_1 2017-06-27
  • 打赏
  • 举报
回复
引用 4 楼 qq_29594393 的回复:
css 设置过渡时间 ,transition:height 2s; 然后js 设置收起 height ="0px" display="none" 展开的话 ,display="block" height="xxx"; 就会有一个过渡的动画效果
大神 我是id属性 css属性覆盖不了啊
当作看不见 2017-06-27
  • 打赏
  • 举报
回复
css 设置过渡时间 ,transition:height 2s; 然后js 设置收起 height ="0px" display="none" 展开的话 ,display="block" height="xxx"; 就会有一个过渡的动画效果
qingwadaxia_1 2017-06-27
  • 打赏
  • 举报
回复
引用 1 楼 zpjshiwo77 的回复:
http://www.w3school.com.cn/jquery/jquery_slide.asp jquery 滑动效果, 不想用jquery写,就用css3动画写,写好一个class,然后给元素加上class就行。
不用jquery的
qingwadaxia_1 2017-06-27
  • 打赏
  • 举报
回复
引用 1 楼 zpjshiwo77 的回复:
http://www.w3school.com.cn/jquery/jquery_slide.asp jquery 滑动效果, 不想用jquery写,就用css3动画写,写好一个class,然后给元素加上class就行。
有具体代码看下吗 大神
zpjshiwo77 2017-06-27
  • 打赏
  • 举报
回复
http://www.w3school.com.cn/jquery/jquery_slide.asp jquery 滑动效果, 不想用jquery写,就用css3动画写,写好一个class,然后给元素加上class就行。

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧