2019-11-02 首页

index.gif

html 代码的布局分为top 和 content
content 分为 左侧的 sidebar 和 main 这两部分内容

  • 代码 html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../../static/css/homepage.css">
    <link rel="stylesheet" type="text/css" href="../../static/css/icon/iconfont.css">
    <script src="../../static/JQuery3.4.1/jquery-3.4.1.min.js"></script>
</head>
<body>
<div class="cantian">
    <div class="top">
        <div class="top-title">
            <img src="../../static/img/demo.png">
            <span>System manager</span>
        </div>
        <div class="top-user">
            <img id="user-img" class="log-img dropdown" src="../../static/img/user1.jpg">
            <span class="log-name">Admin</span>
            <span><i class="iconfont" style="font-size:25px;">&#xe65a;</i></span>
        </div>
        <div class="top-drop-menu dropdown" id="dropmenu">
            <div class="profile-info">
                <h4 class="username">Scott White</h4>
            </div>
            <ul class="action">
                <li class="litest">
                    <a href="#">
                        Profile
                    </a>
                </li>
                <li>
                    <a href="#">
                        <span class="badge badge-danger pull-right">5</span>
                        My Inbox
                    </a>
                </li>
                <li>
                    <a href="#">
                        Setting
                    </a>
                </li>
                <li>
                    <a href="#">
                        Logout
                    </a>
                </li>
            </ul>
        </div>
    </div>
    <div class="content">
        <div id="mySidebar" class="sidebar" >
            <a id="user-a" href="#"><span><i class="iconfont">&#xe7cf;</i><span class="icon-text">用户</span></span></a><br>
            <a id="role-a" href="#"><span><i class="iconfont">&#xe882;</i><span class="icon-text">角色</span></span></a>
            </a><br>
            <a id="power-a" href="#"><span><i class="iconfont">&#xe7dc;</i><span class="icon-text">权限</span></span></a><br>
            <a href="#"><span><i class="iconfont">&#xe7d0;</i><span class="icon-text">资源</span></span></a>
        </div>

        <div id="main">
            <!--<h2>A simple sidebar.</h2>-->
            <!--<p>The sidebar is in fixed position and does not close.</p>-->
            <iframe id="main-iframe" style="width: 100%;height: 100%;border:none" src="userpage"></iframe>
        </div>
    </div>
</div>
</body>
<script src="../../static/js/homepage.js"></script>
</html>
  • css 代码
    布局上使用了 position :absolute 把top 固定再最上方 高度为100px
    其中左侧栏的滑动动画由如下图的css 所示


    image.png
* {
    margin: 0;
    padding: 0;
}

html{
    margin: 0;
    padding: 0;
}

.top{
    position: absolute;
    height: 100px;
    width: 100%;
    background-color: #595959;
}

.top .top-title{
    position: absolute;
    width: 600px;
    height: 100px;
    left: 10px;
    line-height: 100px;
    /*font-size:0;*/
}

.top .top-title * , .top .top-user *{
    color: #fefeff;
    display:inline-block;vertical-align:middle;
}

.top .top-title span{
    font-size: 35px;
}

.top .top-title .top-img{

    height: 100px;
    width: 100px;
    line-height: 100px;
    display: inline-block;
}

.top .top-title .top-name{
    width: 200px;
    height: 100px;
    display: inline-block;
    line-height: 100px;
    /*background-color: #1f6377;*/
}

.top .top-user{
    position: absolute;
    right: 15px;
    height: 100px;
    line-height: 100px;
}

.top .top-user img{
    width: 64px;
    height: 64px;
    border-radius:100%;
    margin-right: 10px;
}

.top .top-user span{
    font-size:15px;
}

.top .top-drop-menu{
    position: absolute;
    right: 0px;
    top:100px;
    background-color: #cc2936;
    border-radius:5px;
    min-width: 300px;
    color: #fefeff;
    /*opacity:0;*/
    /*visibility:hidden;*/
    display:none;
    z-index:1;
}

.action li:hover{
    background-color: #64A6BD;
}
.profile-info{
    background-color: #64A6BD;
}

.top .top-drop-menu div h4 ,.top .top-drop-menu ul li{
    padding: 12px;
    border-bottom: 1px solid #595959;
}

/*后期放到一个公共的Common 的js 中*/
a{
    /*去掉下划线*/
    text-decoration:none;
    color: #fefeff;
}

.top .top-drop-menu ul{
    list-style-type: none;
    font-size: 12px;
}

.content{
    position: absolute;
    top: 100px;
    bottom: 0px;
    width: 100%;
    /*background-color: #1f6377;*/
}

.content .sidebar{
    /*绝对定位,(固定定位)*/
    position: fixed;
    top:100px;
    background-color: #CC2936;
    bottom: 0px;
    height: 100%;
    width: 80px;
    padding-top: 10px;
    /*是文本不换行*/
    white-space: nowrap;
    overflow-x:hidden;
    z-index: 1;
    transition: 0.5s;
}

.content .sidebar a{
    padding: 8px 8px 8px 32px;
    color: #f5dd9b;
    font-size: 18px;
    display:block;
}

.content .sidebar a:hover{
    color: #fefeff;
}
.content .sidebar span i{
    margin-right: 32px;
}
.content #main{
    height: 100%;
    transition: margin-left 0.5s;
    margin-left: 80px;
}
  • js代码
$(function () {
    //侧滑
    $("#mySidebar").hover(toggleSlideBar);
    initAOnclick();
    //登出的下拉动作
    let btn = document.getElementById('user-img');
    let box = document.getElementById('dropmenu');
    let timer = null;
    box.onmouseover = btn.onmouseover = function () {
        if (timer) clearTimeout(timer)
        box.style.display = 'block';
        console.log("mouserover");
    }
    box.onmouseout = btn.onmouseout = function () {
        timer = setTimeout(function () {
            box.style.display = 'none';
        }, 100);
        console.log("mouserout");
    }
})

// 为true 时 侧边栏处于 缩小 状态 变为 扩展状态
let toggleFlag = true;
function toggleSlideBar() {
    if (toggleFlag) {
        $(".sidebar").width(200);
        $("#main").css("marginLeft", "200px");
        console.log("toggleFlag:" + toggleFlag);
        toggleFlag = false;
        console.log("open sideBar");
    } else {
        $(".sidebar").width(80);
        $("#main").css("marginLeft", "80px");
        toggleFlag = true;
        console.log("close sideBar");
    }
}

/**
 * 左侧侧滑列表点击事件
 * @param content   url
 */
function slideBarOnClick(content){
    $("#main-iframe").attr("src",content);
}

function initAOnclick(){
    $("#user-a").click(function(){
        slideBarOnClick("userpage")
    });

    $("#role-a").click(function(){
        slideBarOnClick("rolepage")
    });

    $("#power-a").click(function(){
        slideBarOnClick("powerpage")
    });

    // $("#user-a").click(function(){
    //     slideBarOnClick("userpage")
    // });
}

//左侧栏划入
function sidebarIn() {
    console.log("in");
}

function sidebarOut() {
    console.log("out");
    console.log("ooo");
}
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,284评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,115评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,614评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,671评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,699评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,562评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,309评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,223评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,668评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,859评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,981评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,705评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,310评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,904评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,023评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,146评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,933评论 2 355

推荐阅读更多精彩内容

  • 第一部分HTML&CSS整理答案1.什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HTML5...
    Programmer客栈阅读 2,013评论 0 12
  • 各种纯css图标 CSS3可以实现很多漂亮的图形,我收集了32种图形,在下面列出。直接用CSS3画出这些图形,要比...
    剑残阅读 9,548评论 0 8
  • 本文主要是起笔记的作用,内容来自慕课网. 认识CSS样式 CSS全称为“层叠样式表 (Cascading Styl...
    0o冻僵的企鹅o0阅读 2,643评论 0 30
  • 芭蕉睡鹅阅读 178评论 0 0
  • 来不及看见夏花的灿烂,便已匆匆凋零,来不及欣赏秋叶的静美,便已沉寂无声。来不及迎接猝不及防的青春岁月,青春便一日...
    二三三三a阅读 638评论 3 9