mirror of
https://gitee.com/coder-xiaomo/algorithm-visualization
synced 2025-09-11 06:51:40 +08:00
添加导航栏
This commit is contained in:
@@ -6,11 +6,44 @@ body,
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: rgb(28, 85, 255);
|
||||
}
|
||||
a:hover {
|
||||
text-shadow: 0 0 2px #b9b9b9;
|
||||
}
|
||||
|
||||
.main {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
/* 导航栏 */
|
||||
#header {
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
/* background-color: blue; */
|
||||
box-shadow: 0 0 5px #888;
|
||||
}
|
||||
|
||||
#header-wapper {
|
||||
display: grid;
|
||||
height: 100%;
|
||||
margin: 0 6vw;
|
||||
/* background-color: red; */
|
||||
grid-template-columns: 300px 1fr 300px;
|
||||
}
|
||||
|
||||
.header-logo-image {
|
||||
height: 48px;
|
||||
margin: auto 0;
|
||||
}
|
||||
|
||||
/* 正文 */
|
||||
#container {
|
||||
border: 1px solid #999;
|
||||
border-radius: 5px;
|
||||
|
BIN
src/assets/image/logo-normal-resize-compressed.png
Normal file
BIN
src/assets/image/logo-normal-resize-compressed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
89
src/assets/js/header.js
Normal file
89
src/assets/js/header.js
Normal file
@@ -0,0 +1,89 @@
|
||||
function drawNavbar() {
|
||||
function createElement(json) {
|
||||
if (!json || json.length === 0)
|
||||
return null
|
||||
console.log(1)
|
||||
var fr = document.createDocumentFragment()
|
||||
// var elList = []
|
||||
for (let i = 0; i < json.length; i++) {
|
||||
const element = json[i];
|
||||
// 创建元素
|
||||
var el = document.createElement(element.tagName)
|
||||
// 设置属性
|
||||
if (element.attr) {
|
||||
Object.keys(element.attr).forEach(attrName => {
|
||||
el.setAttribute(attrName, element.attr[attrName])
|
||||
})
|
||||
}
|
||||
// 设置 inner HTML
|
||||
if (element.innerHTML) {
|
||||
el.innerHTML = element.innerHTML
|
||||
}
|
||||
// 创建子元素并插入
|
||||
if (element.childNode) {
|
||||
var childNodeElement = createElement(element.childNode)
|
||||
el.appendChild(childNodeElement)
|
||||
}
|
||||
|
||||
// 将当前元素插入父级元素
|
||||
// elList.push(el)
|
||||
fr.appendChild(el)
|
||||
}
|
||||
// 返回
|
||||
return fr
|
||||
// return elList
|
||||
}
|
||||
|
||||
var headerDOM = document.getElementById("header")
|
||||
var headerHTML = createElement([
|
||||
{
|
||||
"tagName": "div",
|
||||
"attr": {
|
||||
"id": "header-wapper",
|
||||
"style": "opacity: 0; transition: 0.5s"
|
||||
},
|
||||
"childNode": [
|
||||
{
|
||||
"tagName": "img",
|
||||
"attr": {
|
||||
"class": "header-logo-image",
|
||||
"src": "./assets/image/logo-normal-resize-compressed.png",
|
||||
"alt": "小墨算法可视化",
|
||||
},
|
||||
},
|
||||
{
|
||||
"tagName": "div",
|
||||
},
|
||||
{
|
||||
"tagName": "div",
|
||||
"attr": {
|
||||
"class": "header-logo-links",
|
||||
"style": "text-align: right;",
|
||||
},
|
||||
"childNode": [
|
||||
{
|
||||
"tagName": "a",
|
||||
"attr": {
|
||||
"style": "line-height: 60px;",
|
||||
"href": "https://space.bilibili.com/457109942",
|
||||
"target": "_blank",
|
||||
},
|
||||
"innerHTML": "B站"
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
])
|
||||
console.log(headerHTML)
|
||||
if (headerDOM && headerHTML) {
|
||||
headerDOM.appendChild(headerHTML)
|
||||
setTimeout(function () {
|
||||
headerDOM.querySelector("#header-wapper").style.opacity = 1
|
||||
})
|
||||
} else {
|
||||
console.log("找不到 header 容器或 header 容器内容为空")
|
||||
}
|
||||
}
|
||||
|
||||
drawNavbar()
|
Reference in New Issue
Block a user