Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm looking for a smart tooltip popup in javascript or jquery [closed]

I am looking for a tooltip popup which is appended to some links on my website.

  • the tooltip popup should fade in when users mouse hovers.
  • the tooltip popup should stay active while the user is navigating in it.
  • the tooltip should popup to the top/bottom or side depending on it's position (e.g. to the bottom if there is not enough space at the top)

popup size

Any idea or recommendation for something like this? Maybe jquery?

like image 937
Lupo Avatar asked Aug 30 '11 17:08

Lupo


People also ask

What is a JavaScript tooltip?

Introduction to JavaScript Tooltip. Tooltip is used for knowing the item details without opening by clicking or hovering the cursor on to it. A tooltip gives a small box with some text about the item on top of the item by clicking or moving the cursor on to it.

What is tooltip pop-up?

A tooltip is pop-up text that is displayed when a user positions the cursor over a control in MicroStrategy Web.

How do I show tooltip in HTML?

HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .

What is tooltip button?

The tooltip, also known as infotip or hint, is a common graphical user interface (GUI) element in which, when hovering over a screen element or component, a text box displays information about that element, such as a description of a button's function, what an abbreviation stands for, or the exact absolute time stamp ...


1 Answers

The trick is in the CSS, not the JavaScript. First create your popup in static HTML the way you want it to look when active. Then hide it and use .fadeIn() in jQuery.

I'd try something like this:

<a href="foo.htm" class="tooltip">
    Foo
    <div>Tooltip content</div>
</a>

CSS:

a.tooltip {
    position: relative;
}
a.tooltip > div {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -150px;
    width: 300px;
}

JavaScript:

$("a.tooltip").hover(function () {
    $("> div", this).fadeIn();
},
function () {
    $("> div", this).fadeOut();
});

Edit: Here's a demo: http://jsfiddle.net/gilly3/b3PjW/. I take back the part about the JavaScript not being the tricky part. Accounting for links on the edges of the screen means plenty of positioning logic. My jsfiddle does a little of it, but doesn't take into account scrollbars or vertical positioning. That may or may not be an issue for you. If it is, a good plugin should do all that for you.

like image 189
gilly3 Avatar answered Sep 21 '22 19:09

gilly3