这是对我之前的问题的跟进。
我需要动态放置引导工具提示。为此,我需要知道触发工具提示的元素的位置(工作正常)以及应该显示的工具提示的宽度:
编辑澄清:我的工具提示是动态生成的,然后插入到内容中。例如,如果它们太靠近屏幕的左边缘,我需要将它们放置在“右”而不是“顶部”。现在我想让工具提示的宽度仅在它实际离开屏幕时才“正确”放置。
$('body').tooltip({
delay: { show: 300, hide: 0 },
selector: '[rel=tooltip]:not([disabled])',
placement: function(tip, element) {
var offsetLeft = $(element).offset().left;
var offsetRight = ( $(window).width() - ( offsetLeft + $(element).outerWidth() ) );
// need help here: how to get the width of the current tooltip?
// currently returns "0" for all elements
var tooltipWidth = $(tip).outerWidth();
console.log(tooltipWidth);
if (offsetLeft < 220) {
return 'right';
}
if (offsetRight < 220) {
return 'left';
}
else {
return 'top';
}
}
});
提前致谢。