Add list dynamic background
This commit is contained in:
parent
1b6c1399bb
commit
ee1f7e5aee
3 changed files with 28 additions and 1 deletions
|
@ -7,6 +7,6 @@
|
||||||
<span>Theme️ <a href="https://github.com/nanxiaobei/hugo-paper" rel="noopener" target="_blank">Paper</a></span>
|
<span>Theme️ <a href="https://github.com/nanxiaobei/hugo-paper" rel="noopener" target="_blank">Paper</a></span>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="{{ "highlight.min.js" | absURL }}"></script>
|
<script src="{{ "highlight.min.js" | absURL }}"></script>
|
||||||
<script>hljs.initHighlightingOnLoad();</script>
|
<script src="{{ "main.js" | absURL }}"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</head>
|
</head>
|
||||||
<body class="{{if eq .Kind `page` }}single{{else}}list{{ if .IsHome }} home{{ end }}{{end}}">
|
<body class="{{if eq .Kind `page` }}single{{else}}list{{ if .IsHome }} home{{ end }}{{end}}">
|
||||||
|
{{if ne .Kind `page` }}
|
||||||
|
<div class="list-bg"></div>
|
||||||
|
{{end}}
|
||||||
<header class="header">
|
<header class="header">
|
||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
{{ if .IsHome }}
|
{{ if .IsHome }}
|
||||||
|
|
24
static/main.js
Normal file
24
static/main.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
hljs.initHighlightingOnLoad();
|
||||||
|
|
||||||
|
const listBg = document.querySelector('.list-bg');
|
||||||
|
|
||||||
|
if (listBg) {
|
||||||
|
const halfAnHour = 1000 * 60 * 30;
|
||||||
|
|
||||||
|
function setListBgStyle() {
|
||||||
|
const now = new Date();
|
||||||
|
const time = now.getHours() + now.getMinutes() / 60;
|
||||||
|
|
||||||
|
let opacity = Math.abs(time - 14);
|
||||||
|
opacity = opacity > 12 ? 10 + Math.abs(opacity - 14) : opacity;
|
||||||
|
opacity = Number((opacity / 12).toFixed(2));
|
||||||
|
|
||||||
|
listBg.setAttribute('style', `opacity: ${opacity}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(setListBgStyle);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
requestAnimationFrame(setListBgStyle);
|
||||||
|
}, halfAnHour);
|
||||||
|
}
|
Loading…
Reference in a new issue