1
function l_tooltip(target_items, name) {
2
var tooltip = document.createElement("div");
3
tooltip.classList.add(name);
4
tooltip.id = 'tooltipNew';
5
document.body.appendChild(tooltip);
6
for (var i = 0; i < target_items.length; i++) {
7
var target_item = target_items[i];
8
target_item.setAttribute('data-title', target_item.title);
9
target_item.removeAttribute('title');
10
var tooltip = document.getElementById(name + i);
11
target_item.addEventListener('mouseover', e => {
12
let element = e.target.closest('a');
13
let tooltip = document.getElementById('tooltipNew');
14
tooltip.innerHTML = element.getAttribute('data-title');
15
tooltip.style.left = e.clientX + 15 + 'px';
16
tooltip.style.top = e.clientY + 15 + 'px';
17
}
18
);
19
target_item.addEventListener('mousemove', e => {
20
let element = e.target.closest('a');
21
let tooltip = document.getElementById('tooltipNew');
22
tooltip.innerHTML = element.getAttribute('data-title');
23
tooltip.style.left = e.clientX + 15 + 'px';
24
tooltip.style.top = e.clientY + 15 + 'px';
25
}
26
);
27
target_item.addEventListener('mouseout', e => {
28
let tooltip = document.getElementById('tooltipNew');
29
tooltip.style.left = -9999+'px';
30
tooltip.style.top = -9999+'px';
31
}
32
);
33
}
34
35
}
36
37
38
l_tooltip(document.querySelectorAll(".related_posts_item"),"tooltip-j");