Skip to content

Instantly share code, notes, and snippets.

@jimmyalcala
Created July 23, 2014 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmyalcala/ab5911459697bcc35be6 to your computer and use it in GitHub Desktop.
Save jimmyalcala/ab5911459697bcc35be6 to your computer and use it in GitHub Desktop.
body{
margin:20px;
}
.tt{
text-decoration:underline;
}
tooltip.active {
opacity: 1;
margin-top: 5px;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
-ms-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
}
tooltip.out {
opacity: 0;
margin-top: -20px;
}
tooltip {
position: absolute;
background: #88b7d5;
border: 4px solid #c2e1f5;
}
tooltip:after, tooltip:before {
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
tooltip:after {
border-color: rgba(136, 183, 213, 0);
border-bottom-color: #88b7d5;
border-width: 10px;
margin-left: -10px;
tooltip:before {
border-color: rgba(194, 225, 245, 0);
border-bottom-color: #c2e1f5;
border-width: 16px;
margin-left: -16px;
}
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<br>
<br>
<div class='tt' title="Hi, Somebody here!">
Hello World!
</div>
<br>
<div class='tt' title="Ok , I'm leaving!">
Goodbye World!
</div>
<p>This is an awesome pararagraph with some <spam class='tt' title="Surprise i'm here!">helpful hints</spam > that you may</p>
</body>
</html>
$('.tt').mouseover(function(){
var tt=this;
var p=$(tt).position();
$(this).append( "<tooltip>"+this.title+"</tooltip>" );
var h=$("tooltip").outerHeight(true);
var w=$("tooltip").outerWidth();
$("tooltip").css({top:(p.top+22),left:p.left+45-(w/2)});
});
$('.tt').mouseout(function(){
$("tooltip").remove();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment