For bootstrap 3.xx
1. Add the atMouse: false attribute to the built-in class Tooltip.DEFAULTS {}.
Tooltip.DEFAULTS = { animation: true, placement: 'top', selector: false, template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>', trigger: 'hover focus', title: '', delay: 0, html: false, container: false, atMouse: false, viewport: { selector: 'body', padding: 0 } }
2. Return to line 1368 inside the "Tooltip.prototype.enter" method and change the following code:
if (obj instanceof $.Event) { self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true }
in
if (obj instanceof $.Event) { self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true self.options.mousePos = {posX: obj['pageX'], posY: obj['pageY']} }
3. In addition to the "Tooltip.prototype.show" method, add the following code:
if(this.options.atMouse) { pos['posY'] = this.options.mousePos['posY']; pos['posX'] = this.options.mousePos['posX']; }
before this line of code:
var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
4. We support the body of the Tooltip.prototype.getCalculatedOffset method of the following code:
if(this.options.atMouse) { return placement == 'bottom' ? {top: pos.top + pos.height, left: pos.posX - (actualWidth / 2)} : placement == 'top' ? {top: pos.top - actualHeight, left: pos.posX - (actualWidth / 2)} : placement == 'left' ? {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.posX - actualWidth} : {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.posX} }
5.Call tooltip / popover something like this:
$("[data-toggle='popover']").popover({ html: true, container: 'body', atMouse: true, trigger: 'hover', animation: false, placement: "top auto" });
Work for me.