Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将引导工具提示集中在SVG上?_Svg_Twitter Bootstrap_Tooltip - Fatal编程技术网

如何将引导工具提示集中在SVG上?

如何将引导工具提示集中在SVG上?,svg,twitter-bootstrap,tooltip,Svg,Twitter Bootstrap,Tooltip,我想将工具提示向右移动几个像素,使箭头位于光标所在单元格的中心(当前,它位于(0,0),即左上角)。这是我的代码: $("rect.cell").tooltip({ title: "hola", placement: "top" }); 还有一个图像: 理想情况下,我希望使用javascript来实现这一点,因此,如果我更改单元格的大小,我可以更新像素的数量。这似乎是Firefox/Chrome中SVG元素的一个bug(就像我的情况一样) 因此,我刚刚更改了bootst

我想将工具提示向右移动几个像素,使箭头位于光标所在单元格的中心(当前,它位于(0,0),即左上角)。这是我的代码:

 $("rect.cell").tooltip({
    title: "hola",
    placement: "top"
  });
还有一个图像:


理想情况下,我希望使用javascript来实现这一点,因此,如果我更改单元格的大小,我可以更新像素的数量。

这似乎是Firefox/Chrome中SVG元素的一个bug(就像我的情况一样)

因此,我刚刚更改了bootstrap-tooltip.js:

getPosition: function (inside) {
  return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
    width: this.$element[0].offsetWidth
  , height: this.$element[0].offsetHeight
  })
}
为此:

getPosition: function (inside) {
  return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
    width: this.$element[0].getBBox().width
  , height: this.$element[0].getBBox().height
  })
}

我发现在Chrome(适当的高度,但定位在svg:rect元素的最左边)和Firefox(适当的高度,完全不正确的x位置)中,定位是不可靠的。我一直在使用用于jQuery的svgdom插件(不确定这是否会影响我的结果),但我提出了以下解决方案:

这与组合boostrap.js有所不同。以下是其他人针对bootstrap提出的长期休眠问题:


以下是nachocab的getPosition实现的简单扩展,它支持常规HTML元素和SVG元素:

getPosition: function (inside) {
  var el = this.$element[0]
  var width, height

  if ('http://www.w3.org/2000/svg' === el.namespaceURI) {
      var bbox = el.getBBox()
      width = bbox.width
      height = bbox.height
  } else {
      width = el.offsetWidth
      height = el.offsetHeight
  }

  return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
    'width': width
  , 'height': height
  })
}

你能发布一些HTML吗?默认行为是将工具提示居中,因此我想知道您选择的单元格是否为0px或类似的奇怪值。