如何使用光标移动qtip工具提示 [英] How to make a qtip tooltip move with cursor

查看:67
本文介绍了如何使用光标移动qtip工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用js库qtip工具提示。当我将鼠标悬停在表格中的悬停行上时,我想用我的光标移动qtip工具提示。我知道如何使用我的光标使我自己的工具提示移动,但我正在努力与qtip。请解释你回答的代码。谢谢

i am using the js library qtip tooltip. I want to make the qtip tooltip move with my cursor as i hover over the hover row in a table. I know how to make my own tooltip move with my cursor but am struggling with qtip. Please explain the code it you answer. Thanks

我的html:

<table>
    <div id="hoverdiv"></div>
    <tr class="hover" hovertext="Some text">
        <td>Total Credits</td>
        <td><%= @total_credit %></td>
    </tr>
</table>

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

I can create a normal tooltip(without qtip js lib) to follow my cursor using the following jquery code

$(document).ready(function() {
$('.hover').mousemove(function(e) {

    var hovertext = $(this).attr('hovertext');
    $('#hoverdiv').text(hovertext).show();
    $('#hoverdiv').css('top', e.clientY+10).css('left', e.clientX+10);

}).mouseout(function() {

    $('#hoverdiv').hide();

});
});

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

And the code to display a static qtip tooltip:

$(document).ready(function() {
 $('.hover').each(function() {
  $(this).qtip({
     content: $(this).attr('hovertext')
  });
 });
});

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

This is what i have tried so far:

$(document).ready(function() {
$('.hover').mousemove(function(e) {

    $(this).qtip({
     content: $(this).attr('hovertext')
  });
    $('').css('top', e.clientY+10).css('left', e.clientX+10);
});
});


推荐答案

根据 qTip docs

According to the qTip docs:


当position.target设置为鼠标时,此选项确定
当鼠标悬停在
show.target上时工具提示是否跟随鼠标。

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

示例:

$('.selector').qtip({
   content: {
      text: 'I follow the mouse whilst I\'m visible. Weeeeee!'
   },
   position: {
      target: 'mouse',
      adjust: {
         mouse: true  // Can be omitted (e.g. default behaviour)
      }
   }
});

还有 jsFiddle示例

And a jsFiddle example.

这篇关于如何使用光标移动qtip工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆