MediaWiki:Common.js: Difference between revisions
From LOTR-TCG Wiki
No edit summary |
No edit summary |
||
| Line 13: | Line 13: | ||
if ((tooltip_rect.x + tooltip_rect.width + xoffset) > window.innerWidth) // Out on the right | if ((tooltip_rect.x + tooltip_rect.width + xoffset) > window.innerWidth) // Out on the right | ||
x = -tooltip_rect.width | x = window.innerWidth - tooltip_rect.width; | ||
if ((tooltip_rect.y + tooltip_rect.height + yoffset) > window.innerHeight) // Out on the bottom | if ((tooltip_rect.y + tooltip_rect.height + yoffset) > window.innerHeight) // Out on the bottom | ||
y = -tooltip_rect.height | y = window.innerHeight - tooltip_rect.height; // Align on the top | ||
console.log("X: " + x); | console.log("X: " + x); | ||
Revision as of 20:15, 28 September 2021
/* Any JavaScript here will be loaded for all users on every page load. */
var tooltips = document.querySelectorAll('.tooltip span');
window.onmousemove = function (e) {
var xoffset = (e.clientX + 20),
yoffset = (e.clientY + 20);
for (var i = 0; i < tooltips.length; i++) {
var x = xoffset, y = yoffset;
var tooltip_rect = tooltips[i].getBoundingClientRect();
console.log(tooltip_rect);
if ((tooltip_rect.x + tooltip_rect.width + xoffset) > window.innerWidth) // Out on the right
x = window.innerWidth - tooltip_rect.width;
if ((tooltip_rect.y + tooltip_rect.height + yoffset) > window.innerHeight) // Out on the bottom
y = window.innerHeight - tooltip_rect.height; // Align on the top
console.log("X: " + x);
console.log("Y: " + y);
tooltips[i].style.top = y + 'px';
tooltips[i].style.left = x + 'px';
}
};