Đối bootstrap 3.x.x
1.Add thuộc tính atMouse: false đến Tooltip.DEFAULTS lớp inline {}.
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.Go vào dòng 1368 bên trong của phương pháp "Tooltip.prototype.enter" và thay đổi đoạn mã sau:
if (obj instanceof $.Event) {
self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true
}
tới:
if (obj instanceof $.Event) {
self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true
self.options.mousePos = {posX: obj['pageX'], posY: obj['pageY']}
}
3.Inside của phương thức "Tooltip.prototype.show" thêm mã sau:
if(this.options.atMouse) {
pos['posY'] = this.options.mousePos['posY'];
pos['posX'] = this.options.mousePos['posX'];
}
trước dòng mã này:
var calculatedOffset = this.getCalculatedOffset(placement, pos,
actualWidth, actualHeight)
4.Prepend cho cơ thể của phương pháp Tooltip.prototype.getCalculatedOffset mã sau:
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 một cái gì đó như thế này:
$("[data-toggle='popover']").popover({
html: true,
container: 'body',
atMouse: true,
trigger: 'hover',
animation: false,
placement: "top auto"
});
Làm việc cho tôi.
bản sao có thể có của [Twitter Bootstrap Popover - Vị trí chèn DOM] (http: // stackoverflow.com/questions/13369306/twitter-bootstrap-popover-dom-insertion-location) – glomad
ithcy, câu hỏi đó là hỏi về cấu trúc mã. Điều này là về vị trí phần tử trong trình duyệt. – isherwood