2012-03-07 27 views
6

我正在使用js庫qtip工具提示。當我將鼠標懸停在表格中的懸停行上時,我希望使用光標移動qtip工具提示。我知道如何讓我自己的工具提示隨着光標移動,但我正在用qtip掙扎。請解釋你回答的代碼。由於如何使光標移動qtip工具提示

我的HTML:

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

我可以創造一個正常的工具提示(不qtip JS LIB)使用下面的jQuery代碼

$(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提示:

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

這是我到目前爲止已經試過:

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

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

回答

11

按照qTip docs

當position.target設定爲鼠標,此選項決定 懸停在 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 example

+0

謝謝你的工作 – Hishalv 2012-03-08 06:52:22

+0

謝謝,它的工作原理! – 2012-04-15 10:13:23

+0

有沒有可能調用我們的功能?當我移動光標時,我想從左到右,從右到左移動提示 – muthu 2012-12-13 15:01:07