diff options
| author | nanxiaobei <nanxiaobei@gmail.com> | 2019-09-15 06:55:10 +0800 |
|---|---|---|
| committer | nanxiaobei <nanxiaobei@gmail.com> | 2019-09-15 06:55:10 +0800 |
| commit | ee1f7e5aeebd848b766f85cc4d0a103a8bccdf5a (patch) | |
| tree | 5823d1c105328e3fd10180b7ab09f448604080bc | |
| parent | 1b6c1399bb0dc2db45181dbe2a282d60994ef2ad (diff) | |
Add list dynamic background
| -rw-r--r-- | layouts/partials/footer.html | 2 | ||||
| -rw-r--r-- | layouts/partials/header.html | 3 | ||||
| -rw-r--r-- | static/main.js | 24 |
3 files changed, 28 insertions, 1 deletions
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index ec90c88..12d7767 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -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> diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 5d04a26..f79c35c 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.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 }} diff --git a/static/main.js b/static/main.js new file mode 100644 index 0000000..10d8fe1 --- /dev/null +++ b/static/main.js @@ -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); +} |
