From 5dab4fb53d2ab84886311c5bb25dc9afbbb4547e Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Sat, 25 Mar 2023 13:06:00 +0000 Subject: [PATCH] Action label, start --- gallery/static/js/lable.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 gallery/static/js/lable.js diff --git a/gallery/static/js/lable.js b/gallery/static/js/lable.js new file mode 100644 index 0000000..4188422 --- /dev/null +++ b/gallery/static/js/lable.js @@ -0,0 +1,25 @@ +document.addEventListener('DOMContentLoaded', function() { + let labels = document.querySelectorAll('[data-label]'); + + for (let i = 0; i < labels.length; i++) { + labels[i].addEventListener('mouseover', function() { + let label = document.createElement('div'); + label.classList.add('label'); + label.innerHTML = this.dataset.label; + + document.body.appendChild(label); + + label.style.left = (this.offsetLeft + this.offsetWidth + 8) + 'px'; + label.style.top = (this.offsetTop + (label.offsetHeight / 2) - 2) + 'px'; + + setTimeout(function() { + label.style.opacity = 1; + }.bind(this), 250); + }); + + labels[i].addEventListener('mouseout', function() { + let label = document.querySelector('.label'); + label.parentNode.removeChild(label); + }); + } +});