我想将工具提示向右移动几个像素,所以箭头位于光标所在单元格的中心(当前位于(0,0),也就是左上方).这是我的代码:
- $("rect.cell").tooltip({
- title: "hola",placement: "top"
- });
和图像:
理想情况下,我想使用javascript这样做,所以我可以更改像素的数量,如果我更改单元格的大小.
解决方法
这是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
- })
- }