看看这个小提琴:http://jsfiddle.net/BramVanroy/tKL8E/
当您将“联系人”转移到其子项“广告”时,工具提示会显示在项目上方而不是旁边。然后,当您用鼠标返回“联系”并再次返回“adverteren”时,工具提示显示正常。怎么会这样?
相关代码:
var condition = offL > ((wW / 2) - $this.width()),
properties = {},
cssProp = {};
if (condition) {
properties = {
"left": (offL - tooltip.width() - 30)
};
} else {
properties = {
"left": (offL + $this.width() + 25)
};
}
$.extend(properties, {
"top": ($this.offset().top + (posT / 2) - (tooltip.height() / 2))
});
tooltip.stop(true).text(title).animate(properties, 300).fadeTo(200, 1);
答案 0 :(得分:0)
这是因为您在设置新文本之前,或在浏览器引擎重新计算元素大小之前,根据工具提示宽度计算左侧位置。
让我再次检查以找到解决方案或解决方法。
<强>更新强> 像这样改变你的代码片段
tooltip.stop(true).text(title); // set the new text here
var condition = offL > ((wW / 2) - $this.width()),
properties = {},
cssProp = {};
if (condition) {
properties = {
"left": (offL - tooltip.width() - 30)
};
} else {
properties = {
"left": (offL + $this.width() + 25)
};
}
$.extend(properties, {
"top": ($this.offset().top + (posT / 2) - (tooltip.height() / 2))
});
//and not here as you use width property to calculate the element position which is being changed when you change element text
tooltip.animate(properties, 300).fadeTo(200, 1);