diff --git a/src/javascripts/jquery.tipsy.js b/src/javascripts/jquery.tipsy.js index f95c063..6556bb6 100644 --- a/src/javascripts/jquery.tipsy.js +++ b/src/javascripts/jquery.tipsy.js @@ -37,6 +37,14 @@ width: this.$element[0].offsetWidth, height: this.$element[0].offsetHeight }); + + var inFixedContainer = this.$element.css("position") === "fixed" + || this.$element.parents().filter(function(i) { return $(this).css("position") === "fixed"; }).length ? true : false; + if (inFixedContainer) { + pos.top -= $(window).scrollTop(); + pos.left -= $(window).scrollLeft(); + $tip.css("position", "fixed"); + } var actualWidth = $tip[0].offsetWidth, actualHeight = $tip[0].offsetHeight, @@ -240,19 +248,19 @@ * component. */ $.fn.tipsy.autoBounds = function(margin, prefer) { - return function() { - var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)}, - boundTop = $(document).scrollTop() + margin, - boundLeft = $(document).scrollLeft() + margin, - $this = $(this); + return function() { + var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)}, + boundTop = $(document).scrollTop() + margin, + boundLeft = $(document).scrollLeft() + margin, + $this = $(this); - if ($this.offset().top < boundTop) dir.ns = 'n'; - if ($this.offset().left < boundLeft) dir.ew = 'w'; - if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e'; - if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's'; + if ($this.offset().top < boundTop) dir.ns = 'n'; + if ($this.offset().left < boundLeft) dir.ew = 'w'; + if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e'; + if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's'; - return dir.ns + (dir.ew ? dir.ew : ''); - } - }; + return dir.ns + (dir.ew ? dir.ew : ''); + } + }; })(jQuery);