-
Tooltip stay in viewport
I have this piece of awesome tooltip jQuery - Open Source
Code:
(function($){
$.fn.BAToolTip = function(options) {
//set up default options
var defaults = {
tipClass: 'tip', //the class name for your tip
tipFadeEasing: 'easeOutQuint', //easing method
tipFadeDuration: 200, //fade duration
tipOpacity: 1, //opacity of tip when mouseover
tipOffset: 10 //offset the tip relative to mouse cursor in pixels
};
var opts = $.extend({}, defaults, options);
return this.each(function() {
var $this = $(this);
$this.mousemove(function(e){
var parentElementOffset = $this.parent().offset();
var xPos = e.pageX - parentElementOffset.left;
var yPos = e.pageY - parentElementOffset.top;
$(this).parent().find('.'+opts.tipClass).css({'top': yPos+opts.tipOffset, 'left' : xPos+opts.tipOffset});
$(this).parent().find('.'+opts.tipClass).css('display', 'block').stop().animate({opacity:opts.tipOpacity},{duration:opts.tipFadeDuration, easing: opts.tipFadeEasing});
})
$this.mouseout(function(){
$('.'+opts.tipClass).stop().animate({opacity:0},{duration:opts.tipFadeDuration, easing: opts.tipFadeEasing, complete: function(){ $(this).css('display', 'none') } });
})
});
};
})(jQuery);
- this tooltip suits for what I need , and its also the only tooltip that can grab content from multiple div's with the same class , also it's fully themeable via css
There is only 1 flaw within , and that is it won't stay in viewport , it stays in one place , and if the page is small you can't see anything of it.
Is there any ways to implement a functionality to always stay in viewport no matter what like other tooltips?