Skip to content
Browse files

Now uses position absolute to avoid detecting scroll position

  • Loading branch information...
1 parent 75452cc commit a89967811e93dac184dacdb7af65689d19046fce Brian Cray committed May 13, 2011
Showing with 13 additions and 13 deletions.
  1. +6 −6 tooltipsy.min.js
  2. +7 −7 tooltipsy.source.js
View
12 tooltipsy.min.js
@@ -10,15 +10,15 @@
* - className: DOM class for styling tooltips with CSS. Defaults to "tooltipsy"
* More information visit http://tooltipsy.com/
*/
-(function($){$.tooltipsy=function(el,options){var base=this;base.$el=$(el);base.el=el;base.random=parseInt(Math.random()*10000);base.shown=false;base.width=0;base.height=0;base.$el.data("tooltipsy",base);base.init=function(){base.settings=$.extend({},$.tooltipsy.defaults,options);base.$el.bind('mouseenter',function(e){if(base.shown==false){base.shown=true;base.title=base.$el.attr('title')||'';base.$el.attr('title','');base.$tipsy=$('<div id="tooltipsy'+base.random+'">').appendTo('body').css({position:'fixed',zIndex:'999'}).hide();base.$tip=$('<div class="'+base.settings.className+'">').appendTo(base.$tipsy).html(base.settings.content!=''?base.settings.content:base.title);if((function(o){var s=0,k;for(k in o){if(o.hasOwnProperty(k)){s++;}}
+(function($){$.tooltipsy=function(el,options){var base=this;base.$el=$(el);base.el=el;base.random=parseInt(Math.random()*10000);base.shown=false;base.width=0;base.height=0;base.$el.data("tooltipsy",base);base.init=function(){base.settings=$.extend({},$.tooltipsy.defaults,options);base.$el.bind('mouseenter',function(e){if(base.shown==false){base.shown=true;base.title=base.$el.attr('title')||'';base.$el.attr('title','');base.$tipsy=$('<div id="tooltipsy'+base.random+'">').appendTo('body').css({position:'absolute',zIndex:'999'}).hide();base.$tip=$('<div class="'+base.settings.className+'">').appendTo(base.$tipsy).html(base.settings.content!=''?base.settings.content:base.title);if((function(o){var s=0,k;for(k in o){if(o.hasOwnProperty(k)){s++;}}
return s;})(base.settings.css)>0){base.$tip.css(base.settings.css);}
base.width=base.$tipsy.outerWidth();base.height=base.$tipsy.outerHeight();}
if(base.settings.alignTo=='cursor'){var tip_position=[e.pageX-window.pageXOffset+base.settings.offset[0],e.pageY-window.pageYOffset+base.settings.offset[1]];var tip_css={top:tip_position[1]+'px',right:$(window).width()-tip_position[0]+'px',left:'auto'};}
-else{var tip_position=[(function(pos){if(base.settings.offset[0]<0){return(pos.left-window.pageXOffset)-Math.abs(base.settings.offset[0])-base.width;}
-else if(base.settings.offset[0]==0){return(pos.left-window.pageXOffset)-((base.width-base.$el.outerWidth())/2);}
-else{return(pos.left-window.pageXOffset)+base.$el.outerWidth()+base.settings.offset[0];}})(base.$el.offset()),(function(pos){if(base.settings.offset[1]<0){return(pos.top-window.pageYOffset)-Math.abs(base.settings.offset[1])-base.height;}
-else if(base.settings.offset[1]==0){return(pos.top-window.pageYOffset)-((base.height-base.$el.outerHeight())/2);}
-else{return(pos.top-window.pageYOffset)+base.$el.outerHeight()+base.settings.offset[1];}})(base.$el.offset())];}
+else{var tip_position=[(function(pos){if(base.settings.offset[0]<0){return pos.left-Math.abs(base.settings.offset[0])-base.width;}
+else if(base.settings.offset[0]==0){return pos.left-((base.width-base.$el.outerWidth())/2);}
+else{return pos.left+base.$el.outerWidth()+base.settings.offset[0];}})(base.$el.offset()),(function(pos){if(base.settings.offset[1]<0){return pos.top-Math.abs(base.settings.offset[1])-base.height;}
+else if(base.settings.offset[1]==0){return pos.top-((base.height-base.$el.outerHeight())/2);}
+else{return pos.top+base.$el.outerHeight()+base.settings.offset[1];}})(base.$el.offset())];}
base.$tipsy.css({top:tip_position[1]+'px',left:tip_position[0]+'px'});base.settings.show(e,base.$tipsy.stop(true,true));}).bind('mouseleave',function(e){if(e.relatedTarget==base.$tip[0]){base.$tip.bind('mouseleave',function(e){if(e.relatedTarget==base.$el[0]){return;}
base.settings.hide(e,base.$tipsy.stop(true,true));});return;}
base.settings.hide(e,base.$tipsy.stop(true,true));});};base.init();};$.tooltipsy.defaults={alignTo:'element',offset:[0,-1],content:'',show:function(e,$el){$el.css('opacity','1').show(100);},hide:function(e,$el){$el.fadeOut(100);},css:{},className:'tooltipsy'};$.fn.tooltipsy=function(options){return this.each(function(){new $.tooltipsy(this,options);});};})(jQuery);
View
14 tooltipsy.source.js
@@ -32,7 +32,7 @@
base.shown = true;
base.title = base.$el.attr('title') || '';
base.$el.attr('title', '');
- base.$tipsy = $('<div id="tooltipsy' + base.random + '">').appendTo('body').css({position: 'fixed', zIndex: '999'}).hide();
+ base.$tipsy = $('<div id="tooltipsy' + base.random + '">').appendTo('body').css({position: 'absolute', zIndex: '999'}).hide();
base.$tip = $('<div class="' + base.settings.className + '">').appendTo(base.$tipsy).html(base.settings.content != '' ? base.settings.content : base.title);
if ((function (o) {
var s = 0, k;
@@ -57,24 +57,24 @@
var tip_position = [
(function (pos) {
if (base.settings.offset[0] < 0) {
- return (pos.left - window.pageXOffset) - Math.abs(base.settings.offset[0]) - base.width;
+ return pos.left - Math.abs(base.settings.offset[0]) - base.width;
}
else if (base.settings.offset[0] == 0) {
- return (pos.left - window.pageXOffset) - ((base.width - base.$el.outerWidth()) / 2);
+ return pos.left - ((base.width - base.$el.outerWidth()) / 2);
}
else {
- return (pos.left - window.pageXOffset) + base.$el.outerWidth() + base.settings.offset[0];
+ return pos.left + base.$el.outerWidth() + base.settings.offset[0];
}
})(base.$el.offset()),
(function (pos) {
if (base.settings.offset[1] < 0) {
- return (pos.top - window.pageYOffset) - Math.abs(base.settings.offset[1]) - base.height;
+ return pos.top - Math.abs(base.settings.offset[1]) - base.height;
}
else if (base.settings.offset[1] == 0) {
- return (pos.top - window.pageYOffset) - ((base.height - base.$el.outerHeight()) / 2);
+ return pos.top - ((base.height - base.$el.outerHeight()) / 2);
}
else {
- return (pos.top - window.pageYOffset) + base.$el.outerHeight() + base.settings.offset[1];
+ return pos.top + base.$el.outerHeight() + base.settings.offset[1];
}
})(base.$el.offset())
];

0 comments on commit a899678

Please sign in to comment.
Something went wrong with that request. Please try again.