I have an element and on mouseover, I show up additional information
document.getElementById(item.id).getElementsByTagName("div")[0].classList.add(classes.hoverDescription)
.treeNodeDescription{
font-family: "liberation-sans", sans-serif;
font-weight: 400;
font-style: normal;
font-size: 13px;
padding: 5px;
background-color: #333333;
color: #F8F7F7;
padding: 10px;
border-radius: 10px;
display: none;
position: absolute;
top: 130%;
left: 21%;
z-index: 10;
max-width: 300px;
text-wrap: wrap;
}
.hoverDescription{
display: block;
}
But I ‘d like to show the tooltip after a 3 seconds wait time. And hide it on mouse leave.
How to do it using JavaScript or CSS?
3
Answers
Plz insert this script tag in your html file.
I’ve made an example, based on what you explained I believe you want something like this, We need to see your HTML in order to tailor it exactly for your setup. But you can adapt this function to your needs.
Show a hidden element only when you hover on a parent for a set amount of time, hide the element when you no longer hover over it:
I’ll suggest a CSS-only solution because: JavaScript is not necessary.
To show a tooltip on hover, all it takes is, well, to use
:hover
. And for the appearing delay you can use thedelay
value for your CSSanimation
.Also, by using CSS Properties you can assign to each tooltip a desired
style="--delay:3sec;"
in the tooltip’s style attribute – to customize the necessary delay:Tip: Better UX with a wait loader?
Why not, move the
style="--delay:3s;"
to the parent element, and add a::before
pseudo element for the loader: