简易后台效果

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理信息</title>
    <link rel="stylesheet" href="./css/index.css">
</head>

<body>
    <div class="box">
        <div class="header">
            <div class="top_fl">后台管理系统</div>
            <div class="top_ri"></div>
        </div>
        <div class="body">
            <div class="body_fl">
                <div class="b_fl">个人资料</div>
                <div class="b_fl">相册管理</div>
                <div class="b_fl">日志管理</div>
                <div class="b_fl">留言管理</div>
                <div class="b_fl">风格管理</div>
                <div class="b_fl">系统管理</div>
                <div class="b_fl">帮助信息</div>
            </div>
            
            <div class="body_ri">欢迎使用管理系统!</div>
        <div class="foot"></div>
    </div>
</body>
<script src="./js/index.js"></script>
</html>
* {
    margin: 0;
    padding: 0;
    user-select: none;
}
html,body {
    height: 100%;
}
body {
    display: flex;
    justify-content: center;
    align-items: center;
}
.box {
    width: 900px;
}
.header {
    width: 900px;
    height: 40px;
    display: flex;
}
.top_fl {
    width: 150px;
    height: 40px;
    background-color: #aaa;
    text-align: center;
    line-height: 40px;
    font-weight: 900;
}
.top_ri {
    width: 750px;
    height: 40px;
    background-color: #ccccc0;
    display: flex;
}

.body {
    height: 500px;
    width: 900px;
}

.body_fl {
    width: 150px;
    height: 500px;
    background-color: #ddd;
    float: left;
    cursor: pointer;
}

.body_fl .b_fl {
    width: 130px;
    height: 30px;
    background-color: #fff;
    text-align: center;
    line-height: 30px;
    font-weight: 500;
    margin: 15px auto;
}

.body_ri {
    width: calc(100% - 150px);
    height: 500px;
    background-color: floralwhite;
    float: right;
    text-align: center;
    font-weight: 900;
}
/* .body .atv {
    display: block;
} */


.foot {
    width: 900px;
    height: 30px;
    background-color: #ccccc0;
}
.top_ri .atv {
    background-color: pink !important;
}
function System () {
    //点击左侧的内容,在上面创建一个一模一样的标签,单独设置一下样式
    //如果点击的标签上面已经存在了,就不需要创建了,直接切换到
    //上面创建好的标签,且还是高亮的状态,点击的时候判断是否有标记,没标记
    //就创建标记,且复制标签放到上面,如果有标记,就直接跳转到上面的标签
    this.fl = document.querySelector('.body_fl');
    this.fl.className = 'body_fl box'
    console.dir(this.fl);
    this.top_ri = document.querySelector('.top_ri');
    this.click();
    this.clickk();

}
//点击事件方法
System.prototype.click = function () {
    //事件委托
    this.fl.onclick = () => {
        const target = window.event.target;
        if(target.className === 'b_fl') {
            //判断
            this.sense(target);
        }
    }
}

System.prototype.sense = function (target) {
    if (!target.getAttribute('id')) {
        target.setAttribute('id',+new Date());
        let kr = target.cloneNode(true);
        this.top_ri.appendChild(kr);
        this.Style(kr,{
            width : '100px',
            height : '40px',
            backgroundColor : '#fc0',
            textAlign: 'center',
            lineHeight: '40px',
            fontWeight: '500',
            marginRight : '5px'
        });
        //创建元素
        this.creator(kr);
    }
    // else if(target.getAttribute('id') == this.top_ri.children.getAttribute('id')) {
    //     console.log(2)
    // }

    else {
        let id = target.getAttribute('id');
        for(let i = 0; i < this.top_ri.children.length; i++) {
            for (let j = 0; j < this.top_ri.children.length; j++) {
                this.top_ri.children[i].className = 'b_fl'
            }
            if(id == this.top_ri.children[i].getAttribute('id')) {
                // this.top_ri.children[i].className = 'b_fl atv'
                this.top_ri.children[i].classList.add('atv')
            }
        }
    }
}
//创建span标签
System.prototype.creator = function (res) {
    let img = document.createElement('img');
    
    img.setAttribute('src','https://hovertree.com/hvtimg/bjafje/wy6cv9nl.gif');
    this.Style(img,{
        width : '14px',
        height : '14px',
    });
    res.appendChild(img)
};
//点击img
System.prototype.clickk = function () {
    this.top_ri.onclick = () => {
        const target = window.event.target;
        if(target.className === 'b_fl') {
            //判断
            for(let i = 0; i < this.top_ri.children.length; i++) {
                this.top_ri.children[i].className = 'b_fl';
            }
            target.className = 'b_fl atv'
        }
        if(target.tagName === 'IMG') {
            console.log()
            for(var i = 0; i < this.fl.children.length; i++) {
                if(target.parentElement.getAttribute('id') == this.fl.children[i].getAttribute('id')) {
                    this.fl.children[i].removeAttribute('id');
                }
            }
            target.parentNode.parentNode.removeChild(target.parentNode);
        }
    }
}
//设置样式的方法
System.prototype.Style = function (ele,obj) {
    for(var key in obj) {
        ele.style[key] = obj[key];
    }
}

new System();

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值