Css 如何将引导工具提示正确放置在部分隐藏的图像旁边
我有以下使用引导工具提示的页面,我无法正确定位 该页面具有以下特征: 外部容器是我的页面。它有固定的宽度。 有很多。内部容器。它们具有固定宽度和溢出-x:auto。 .内部容器是动态生成的。不确定它是否相关,因此下面的示例代码是静态的 内部容器divs中有任意HTML,可以包含许多 图片最初由 大小适中的stackoverflow标志 超长的stackoverflow标志Css 如何将引导工具提示正确放置在部分隐藏的图像旁边,css,twitter-bootstrap-3,overflow,twitter-bootstrap-tooltip,Css,Twitter Bootstrap 3,Overflow,Twitter Bootstrap Tooltip,我有以下使用引导工具提示的页面,我无法正确定位 该页面具有以下特征: 外部容器是我的页面。它有固定的宽度。 有很多。内部容器。它们具有固定宽度和溢出-x:auto。 .内部容器是动态生成的。不确定它是否相关,因此下面的示例代码是静态的 内部容器divs中有任意HTML,可以包含许多 图片最初由 大小适中的stackoverflow标志 超长的stackoverflow标志 多亏了@y34h的创意,但我必须通过重写实际的引导js代码来计算left属性的正确值 以下是新的Tooltip.getCal
多亏了@y34h的创意,但我必须通过重写实际的引导js代码来计算left属性的正确值 以下是新的Tooltip.getCalcultedOffset,它是计算工具提示绝对位置的函数:
$.fn.tooltip.Constructor.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
return placement === 'bottom' ? {
top: pos.top + pos.height,
left: pos.left + pos.width / 2 - actualWidth / 2 } :
placement === 'top' ? {
top: pos.top - actualHeight,
left: pos.left + pos.width / 2 - actualWidth / 2 } :
placement === 'left' ? {
top: pos.top + pos.height / 2 - actualHeight / 2,
left: pos.left - actualWidth } :
/* placement == 'right' */ {
top: pos.top + pos.height / 2 - actualHeight / 2,
left:
/* begin fix */
Math.min(
pos.left + pos.width, //original left
$(".inner-container").offset().left + $(".inner-container")[0].clientWidth //max left
)
/* end fix */
};
};
实际更改包含在/*开始修复*/和/*结束修复中*/
以下是完整的工作代码:
$.fn.tooltip.Constructor.prototype.getCalculatedOffset=函数位置、位置、实际宽度、实际高度{
返回位置=='底部'{
顶部:位置顶部+位置高度,
左:位置左+位置宽度/2-实际宽度/2}:
位置=='顶部'{
顶部:位置顶部-实际高度,
左:位置左+位置宽度/2-实际宽度/2}:
位置=='左'{
顶部:位置顶部+位置高度/2-实际高度/2,
左:位置左-实际宽度}:
/*位置=='右'*/{
顶部:位置顶部+位置高度/2-实际高度/2,
左:
/*开始修复*/
Math.min
位置左侧+位置宽度,//原始左侧
$.internal-container.offset.left+$.internal container[0]。客户端宽度//最大左侧
/*端部固定*/
};
};
$outer-container.tooltip{
选择器:img,
安置:对,,
标题:函数{return$this.attralt;},
};
外容器
{
边框:1px实心;
填充:10px;
宽度:960px;
左边距:自动;
右边距:自动;
溢出:自动;
}
.内胆
{
宽度:600px;
溢出-x:自动;
边框:1px实心;
边缘底部:10px;
浮动:对;
}
图片最初由
大小适中的stackoverflow标志
超长的stackoverflow标志
当图像比.internal container更宽时,此方法有效,但当图像比.internal container更窄时则无效:工具提示仍然显示在.internal container的右边缘,但它应该显示在图像的右边缘。我发现更改left属性是一种方法,但我现在正在用javascript进行计算
$.fn.tooltip.Constructor.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
return placement === 'bottom' ? {
top: pos.top + pos.height,
left: pos.left + pos.width / 2 - actualWidth / 2 } :
placement === 'top' ? {
top: pos.top - actualHeight,
left: pos.left + pos.width / 2 - actualWidth / 2 } :
placement === 'left' ? {
top: pos.top + pos.height / 2 - actualHeight / 2,
left: pos.left - actualWidth } :
/* placement == 'right' */ {
top: pos.top + pos.height / 2 - actualHeight / 2,
left:
/* begin fix */
Math.min(
pos.left + pos.width, //original left
$(".inner-container").offset().left + $(".inner-container")[0].clientWidth //max left
)
/* end fix */
};
};