Fork Of

Revisions

gist: 76414 Download_button fork
public
Public Clone URL: git://gist.github.com/76414.git
Embed All Files: show embed
jquery.tooltip.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// tooltip plugin for jQuery
 
(function($) {
  $.fn.tooltip = function(options) {
    var options = $.extend({
      xOffset: 30,
      yOffset: 7,
      follow: false
    }, options)
  
    return this.each(function() {
      $(this).hover(function(e) {
      
        // prevent duplicate "hovers"
        this._title = this.title
        this.title = ''
      
        $('body').append('<p id="tooltip">' + this._title + '</p>')
        $('#tooltip').
          css('top', (e.pageY - options.yOffset) + 'px').
          css('left', (e.pageX + options.xOffset) + 'px').
          fadeIn('fast')
      }, function() {
        this.title = this._title
        $('#tooltip').remove()
      })
    
      // supports the option to follow the
      // tooltip wherever the cursor goes
      if (options.follow) {
        $(this).mousemove(function(e) {
          $('#tooltip').
            css('top', (e.pageY - options.yOffset) + 'px').
            css('left', (e.pageX + options.xOffset) + 'px')
        })
      }
    })
  }
})(jQuery);