Last active
February 14, 2019 02:30
-
-
Save ghedo/955408 to your computer and use it in GitHub Desktop.
Lightweight tooltip plugin for jQuery (http://bl.ocks.org/955408)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Extremely lightweight tooltip plugin for jQuery. | |
* | |
* Copyright 2009 Alessandro Ghedini <[email protected]> | |
* -------------------------------------------------------------- | |
* "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