Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanxiaobei/hugo-paper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authornanxiaobei <nanxiaobei@gmail.com>2019-09-15 01:55:10 +0300
committernanxiaobei <nanxiaobei@gmail.com>2019-09-15 01:55:10 +0300
commitee1f7e5aeebd848b766f85cc4d0a103a8bccdf5a (patch)
tree5823d1c105328e3fd10180b7ab09f448604080bc /static
parent1b6c1399bb0dc2db45181dbe2a282d60994ef2ad (diff)
Add list dynamic background
Diffstat (limited to 'static')
-rw-r--r--static/main.js24
1 files changed, 24 insertions, 0 deletions
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);
+}