Add list dynamic background
This commit is contained in:
parent
1b6c1399bb
commit
ee1f7e5aee
|
@ -7,6 +7,6 @@
|
|||
<span>Theme️ <a href="https://github.com/nanxiaobei/hugo-paper" rel="noopener" target="_blank">Paper</a></span>
|
||||
</footer>
|
||||
<script src="{{ "highlight.min.js" | absURL }}"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script src="{{ "main.js" | absURL }}"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -38,6 +38,9 @@
|
|||
{{ end }}
|
||||
</head>
|
||||
<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">
|
||||
<nav class="nav">
|
||||
{{ if .IsHome }}
|
||||
|
|
|
@ -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 New Issue