Skip to content

Instantly share code, notes, and snippets.

@ghedo
Last active February 14, 2019 02:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghedo/955408 to your computer and use it in GitHub Desktop.
Save ghedo/955408 to your computer and use it in GitHub Desktop.
Lightweight tooltip plugin for jQuery (http://bl.ocks.org/955408)
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="microTip.js"></script>
<title>microTip.js - Extremely lightweight tooltip plugin for jQuery</title>
<style>
p#microtip{
border: 1px solid black;
padding: 10px;
border-radius: 0.5em;
font-size: 10px;
background-color: yellow;
}
</style>
</head>
<body>
<h1>Example of microTip</h1>
<p><a href="#" rel="microtip" title="This is an example of microTip.">Example of microTip</a></p>
</body>
</html>
/*
* Extremely lightweight tooltip plugin for jQuery.
*
* Copyright 2009 Alessandro Ghedini <alessandro@ghedini.me>
* --------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Alessandro Ghedini wrote this file. As long as you retain this
* notice you can do whatever you want with this stuff. If we
* meet some day, and you think this stuff is worth it, you can
* buy me a beer in return.
* --------------------------------------------------------------
*/
this.microtip = function () {
$('a[rel*=microtip]').unbind().hover(
function (obj) {
this.msg = this.title;
this.title = '';
this.top = obj.pageY + 15;
this.left = obj.pageX + 15;
$('body').append('<p id="microtip" style="display:none; position:absolute">' + this.msg + '</p>');
$('p#microtip').css("left", this.left + "px").css("top", this.top + "px");
$('p#microtip').fadeIn("slow");
},
function () {
$("p#microtip").remove();
this.title = this.msg;
}
);
$('a[rel*=microtip]').mousemove(
function (obj) {
this.top = obj.pageY + 15;
this.left = obj.pageX + 15;
$('p#microtip').css("left", this.left+"px").css("top", this.top + "px");
}
);
};
jQuery(document).ready(function ($) { microtip(); })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment