jquery – 如何使用光标移动qtip工具提示

前端之家收集整理的这篇文章主要介绍了jquery – 如何使用光标移动qtip工具提示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用js库qtip工具提示.当我将鼠标悬停在表格中的悬停行上时,我想用我的光标移动qtip工具提示.我知道如何使用我的光标使我自己的工具提示移动,但我正在努力与qtip.请解释你回答的代码.谢谢

我的HTML

  1. <table>
  2. <div id="hoverdiv"></div>
  3. <tr class="hover" hovertext="Some text">
  4. <td>Total Credits</td>
  5. <td><%= @total_credit %></td>
  6. </tr>
  7. </table>

我可以使用以下jquery代码创建一个普通的工具提示(没有qtip js lib)来跟踪我的光标

  1. $(document).ready(function() {
  2. $('.hover').mousemove(function(e) {
  3.  
  4. var hovertext = $(this).attr('hovertext');
  5. $('#hoverdiv').text(hovertext).show();
  6. $('#hoverdiv').css('top',e.clientY+10).css('left',e.clientX+10);
  7.  
  8. }).mouSEOut(function() {
  9.  
  10. $('#hoverdiv').hide();
  11.  
  12. });
  13. });

以及显示静态qtip工具提示代码

  1. $(document).ready(function() {
  2. $('.hover').each(function() {
  3. $(this).qtip({
  4. content: $(this).attr('hovertext')
  5. });
  6. });
  7. });

这是我到目前为止所尝试的:

  1. $(document).ready(function() {
  2. $('.hover').mousemove(function(e) {
  3.  
  4. $(this).qtip({
  5. content: $(this).attr('hovertext')
  6. });
  7. $('').css('top',e.clientX+10);
  8. });
  9. });

解决方法

根据 qTip docs

When the position.target is set to mouse,this option determines
whether the tooltip follows the mouse when hovering over the
show.target.

例:

  1. $('.selector').qtip({
  2. content: {
  3. text: 'I follow the mouse whilst I\'m visible. Weeeeee!'
  4. },position: {
  5. target: 'mouse',adjust: {
  6. mouse: true // Can be omitted (e.g. default behavIoUr)
  7. }
  8. }
  9. });

而且是jsFiddle example.

猜你在找的jQuery相关文章