Created
January 14, 2020 06:44
-
-
Save Jetroid/0ab5e676ab279e19fb245680ada0588d to your computer and use it in GitHub Desktop.
Tooltips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tooltipTimer; | |
var tooltipDiv; | |
var tooltip; | |
var tooltipIn = function(e){ | |
tooltip = e.target; | |
tooltipTimer = setTimeout(function(){ | |
var position = e.target.getBoundingClientRect(); | |
tooltip.classList.add("show"); | |
}, 200); | |
} | |
var tooltipOut = function(e) { | |
clearTimeout(tooltipTimer); | |
tooltip.classList.remove("show"); | |
} | |
var tooltips = Array.from(document.getElementsByClassName("has-tooltip")); | |
tooltips.forEach((tooltip) => { | |
tooltip.addEventListener('mouseenter', function(e) { tooltipIn(e); }) | |
tooltip.addEventListener('mouseleave', function(e) { tooltipOut(e); }); | |
}); | |
.has-tooltip { pointer-events: none; } | |
.has-tooltip::before { | |
content: attr(data-tooltip); | |
position: absolute; | |
background-color: black; | |
color: white; | |
border-radius: 2px; | |
padding: 5px; | |
visibility: hidden; | |
opacity: 0; | |
transition: visibility 0.5s, opacity 0.2s linear; | |
font-family: sans-serif; | |
} | |
.has-tooltip.show::before { | |
opacity: 0.8; | |
visibility: visible; | |
transition: visibility 0.5s, opacity 0.2s linear; | |
} | |
.has-tooltip::after { | |
font-family: "Font Awesome 5 Free"; | |
font-weight: 900; | |
content:"\f059"; | |
pointer-events: all; | |
font-size: 20px; | |
position: absolute; | |
right: 0; | |
top: 7px; | |
} | |
<p class="has-tooltip" data-tooltip="tooltip goes here"> Regular Text Goes Here </p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment