mirror of https://github.com/sveltejs/svelte
25 lines
537 B
25 lines
537 B
<script>
|
|
let container;
|
|
function tooltip(node, text) {
|
|
let tooltip = null;
|
|
|
|
function onVisibilityChange() {
|
|
tooltip = document.createElement('div');
|
|
tooltip.classList.add('tooltip');
|
|
tooltip.textContent = text;
|
|
container.appendChild(tooltip);
|
|
}
|
|
|
|
node.addEventListener('visibilitychange', onVisibilityChange);
|
|
|
|
return {
|
|
destroy() {
|
|
node.removeEventListener('visibilitychange', onVisibilityChange);
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<svelte:document use:tooltip="{'Perform an Action'}" />
|
|
<div bind:this={container} />
|