Created
March 19, 2013 16:41
-
-
Save srobbin/5197731 to your computer and use it in GitHub Desktop.
A CodePen by Scott Robbin. jQuery Plugin Workshop - A sandbox to show students the basics of jQuery plugin authoring.
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
| <h2>Tooltips</h2> | |
| <ul> | |
| <li> | |
| <a href="#" data-tooltip="This is the first tooltip">Tooltip 1</a> | |
| </li> | |
| <li> | |
| <a href="#" data-tooltip="This is the second tooltip">Tooltip 2</a> | |
| </li> | |
| <li> | |
| <a class="third" href="#">Tooltip 3</a> | |
| </li> | |
| </ul> |
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
| // Clear the console | |
| console.clear(); | |
| (function ($) { | |
| $.fn.tooltip = function (text) { | |
| return this.each(function () { | |
| var $self = $(this), | |
| message = text || $self.data("tooltip"); | |
| // Create a container for the tooltip | |
| var $tooltip = $("<div></div>"); | |
| $tooltip | |
| .text(message) | |
| .addClass("tip") | |
| .appendTo($self); | |
| $self | |
| .mouseover(function () { | |
| $tooltip.show(); | |
| }) | |
| .mouseout(function () { | |
| $tooltip.hide(); | |
| }); | |
| }); | |
| }; | |
| $("a[data-tooltip]").tooltip(); | |
| $.expr[':'].tooltip = function (element) { | |
| return $(element).data("tooltip"); | |
| }; | |
| })(jQuery); | |
| $(".third").tooltip("This is another tooltip!"); | |
| $("a:tooltip").css("color", "red"); |
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
| @import "compass"; | |
| body { padding: 10px; } | |
| .tip { | |
| display: none; | |
| position: absolute; | |
| background: #000; | |
| color: white; | |
| padding: 5px | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment