HTML实现双抽屉效果

3 篇文章 0 订阅

记录:

双抽屉效果:


描述:

使用css、js实现效果。


代码块:

<!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>
        #d1,#d3{
            width: 100px;
            height: 100px;
            background-color: red;
            border-radius: 50%;
            text-align: center;
            line-height: 100px;
        }
        #d2{
            width: 500px;
            height: 100%;
            background-color: blue;
            position: absolute;
            right: 0px;
            top: 0px;
            width: 0px;
            transition: width 500ms;
        }
        #d4{
            width: 300px;
            height: 100%;
            background-color: black;
            position: absolute;
            right: 0px;
            top: 0px;
            width: 0px;
            transition: width 500ms;
        }
    </style>
</head>
<body>
    <div id="d1">按钮</div>
    <div id="d2">
        <div id="d3">按钮</div>
        <div id="d4"></div>
    </div>
    <script>
        var d1=document.getElementById("d1");
        var d2=document.getElementById("d2");
        var d3=document.getElementById("d3");
        var d4=document.getElementById("d4");
        var i=0;
        var j=0;
        d1.onclick=function(){
            if (i==0) {
                d2.style.width="500px"
                i=1;
            }else if(i==1){
                d2.style.width="0px"
                d4.style.width="0px"
                i=0;
            }
        }
        d3.onclick=function(){
            if (j==0) {
                d4.style.width="300px"
                j=1;
            }else if(j==1){
                d4.style.width="0px"
                j=0;
            }
        }
        

    </script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值