Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,23 @@ archive_generator:

## 3.1. 基本配置

`background` 参数是一个列表,打开时会随机加载一个背景。
`homeBackground`和`contentBackground` 参数是一个列表,打开时会随机加载一个背景。

`homeBackground`是首页的背景,至少要有一张图片、`contentBackground`是内容,或者说整个网站的背景,默认为空,可置入任意数量的图片。

```yaml
# Avatar image
avatar: /images/avatar.jpg

# Home page background image
background:
- /images/background.jpg
homeBackground:
- /images/home-background.jpg
# - /images/home-background1.jpg

# Content (or global) background image
contentBackground:
# - /images/content-background.jpg
# - /images/content-background1.jpg

# Loading image
loading: /images/loading.gif
Expand Down
8 changes: 6 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
avatar: /images/avatar.jpg

# Home page background image
background:
- /images/background.jpg
homeBackground:
- /images/home-background.jpg

# Content (or global) background image
contentBackground:
# - /images/content-background.jpg

# Loading image
loading: /images/loading.gif
Expand Down
2 changes: 1 addition & 1 deletion layout/index.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="home-head">
<div id="home-background" ref="homeBackground" data-images="<%- theme.background.map(url_for) %>"></div>
<div id="home-background" ref="homeBackground" data-images="<%- theme.homeBackground.map(url_for) %>"></div>
<div id="home-info" @click="homeClick">
<span class="loop"></span>
<span class="loop"></span>
Expand Down
3 changes: 3 additions & 0 deletions layout/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
</head>
<body>
<div id="layout">
<% if (theme.contentBackground) { %>
<div id="content-background" ref="contentBackground" data-images="<%- theme.contentBackground.map(url_for) %>"></div>
<% } %>
<transition name="fade">
<div id="loading" v-show="loading">
<div id="loading-circle">
Expand Down
12 changes: 12 additions & 0 deletions source/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
#archives h3 {
margin: 10px 0;
}
#content-background {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
/* background-image: url(""); */
background-size: cover;
background-position: center;
opacity: 0.3;
z-index: -1;
}
#crypto {
margin: 50px 0;
}
Expand Down
File renamed without changes
15 changes: 11 additions & 4 deletions source/js/lib/home.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
mixins.home = {
mounted() {
let background = this.$refs.homeBackground;
let images = background.dataset.images.split(",");
let id = Math.floor(Math.random() * images.length);
background.style.backgroundImage = `url('${images[id]}')`;
let homeBackgroundRef = this.$refs.homeBackground;
let homeBgImgURLs = homeBackgroundRef.dataset.images.split(",");
homeBackgroundRef.style.backgroundImage = `url('${
homeBgImgURLs[Math.floor(Math.random() * homeBgImgURLs.length)]
}')`;
this.menuColor = true;

let contentBackgroundRef = this.$refs.contentBackground;
let contentBgImgURLs = contentBackgroundRef.dataset.images.split(",");
contentBackgroundRef.style.backgroundImage = `url('${
contentBgImgURLs[Math.floor(Math.random() * contentBgImgURLs.length)]
}')`;
},
methods: {
homeClick() {
Expand Down