如何在绝对定位的图元上正确定位工具提示



我有一堆绝对定位的图像,我正试图根据元素上指定的数据属性让工具提示出现在上面。由于某些原因,工具提示的位置总是关闭的。我已经包含了一个演示。有人能发现这个问题吗?

$("div.thing").each(function (i) {
  var objthis = this;
  $(this).qtip({
    show: 'click',
    hide: 'click',
    content: {
      text: 'hey'
    },
    position: {
      corner: {
        tooltip: 'topLeft',
        target: 'topLeft'
      },
      adjust: {
        x: $(objthis).data('left'),
        y: $(objthis).data('top')
      }
    }
  });
});
div#container {
  position: relative;
  width: 100px;
  height: 100px;
  background-color: black;
}
div.thing {
  position: absolute;
  z-index: 1;
  border: 0;
  height: 10px;
  width: 10px;
  top: 50px;
  left: 20px;
  background-color: red;
}
<link href="http://cdn.jsdelivr.net/qtip2/2.2.1/jquery.qtip.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/qtip2/2.2.1/jquery.qtip.min.js"></script>
<div id="container">
  <div class="thing" data-top="50" data-left="20"></div>
</div>

通过在qtip设置中同时设置offset,工具提示移动得离图像太远。尝试删除偏移:

$("div.thing").each(function (i) {
  var objthis = this;
  $(this).qtip({
    show: 'click',
    hide: 'click',
    content: {
      text: 'hey'
    },
    position: {
      corner: {
        tooltip: 'topLeft',
        target: 'topLeft'
      },
    }
  });
});
div#container {
  position: relative;
  width: 100px;
  height: 100px;
  background-color: black;
}
div.thing {
  position: absolute;
  z-index: 1;
  border: 0;
  height: 10px;
  width: 10px;
  top: 50px;
  left: 20px;
  background-color: red;
}
<link href="http://cdn.jsdelivr.net/qtip2/2.2.1/jquery.qtip.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/qtip2/2.2.1/jquery.qtip.min.js"></script>
<div id="container">
  <div class="thing" data-top="50" data-left="20"></div>
</div>

最新更新