JSFiddle - React, Tailwind, and code Playground
HTML
<p>This is an example text with a <a href="3" data-tooltip="Just click it, genius!">link</a> in it! Cool, huh?</p>
<div class="tooltip"></div>
CSS
.tooltip {
display: none;
padding: 3px 5px;
background-color: #333;
color: #fff;
border-radius: 3px;
font: 13px normal Arial, Helvetica, sans-serif;
opacity: 0.9;
border-left: solid 5px #FF594E;
}
JavaScript
var $link = $('a');
var $tooltip = $('.tooltip');
$link.hover(
function () { // mouseover
var $this = $(this);
var link_offset = $this.offset();
var link_tooltip = $this.data('tooltip');
$tooltip.css({
position: 'absolute',
left: link_offset.left + 'px',
top: (link_offset.top + 30) + 'px',
})
.text(link_tooltip)
.fadeIn(250)
.animate({
top: (link_offset.top + 40) + 'px'
}, 250);
},
function () { // mouseleave
var $this = $(this);
var link_offset = $this.offset();
var link_tooltip = $this.data('tooltip');
$tooltip.animate({
top: (link_offset.top + 30) + 'px'
}, 250).
fadeOut(250, function() {
$(this).removeAttr('style').empty();
});
}
);