mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-23 05:26:15 -04:00
Help update
This commit is contained in:
parent
d31f8ef0b4
commit
b19cc5c0b4
23 changed files with 863 additions and 446 deletions
39
src/tooltip.ts
Normal file
39
src/tooltip.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import {isOptionOn} from "./options";
|
||||
|
||||
export function setupTooltips() {
|
||||
const tooltip = document.getElementById('tooltip') as HTMLDivElement
|
||||
if (isOptionOn('mobile-mode')) {
|
||||
tooltip.style.display = 'none';
|
||||
return
|
||||
}
|
||||
|
||||
function updateTooltipPosition(e:MouseEvent){
|
||||
tooltip.style.transform=`translate(${e.clientX}px,${e.clientY + 20}px) `+(e.clientX > window.innerWidth / 2 ? ' translate(-100%,0)':'')
|
||||
}
|
||||
|
||||
document.body.addEventListener('mouseenter', (e:MouseEvent) => {
|
||||
let parent: HTMLElement | null = e.target as HTMLElement
|
||||
while (parent && !parent.hasAttribute('data-tooltip')) {
|
||||
parent = parent.parentElement
|
||||
}
|
||||
if (parent?.hasAttribute('data-tooltip')) {
|
||||
tooltip.innerHTML = parent?.getAttribute('data-tooltip')
|
||||
tooltip.style.display = '';
|
||||
updateTooltipPosition(e)
|
||||
}else{
|
||||
|
||||
tooltip.style.display = 'none';
|
||||
}
|
||||
}, true)
|
||||
document.body.addEventListener('mousemove', e => {
|
||||
if (!tooltip.style.display) {
|
||||
updateTooltipPosition(e)
|
||||
}
|
||||
}, true)
|
||||
document.body.addEventListener('mouseleave', e => {
|
||||
// tooltip.style.display = 'none';
|
||||
}, true)
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue