2012-02-02 36 views
1

在這裏的一些偉大的人的幫助下,我想要得到一個jQuery懸停工具提示工作:) ..下一步實際上將懸停應用到跨班級而不是鏈接...(因爲我沒有需要他們聯繫......但在未來我可能需要添加一個可點擊的鏈接),所以目前...將動作應用於跨度而不是鏈接?

$(document).ready(function(){ 
    $('.tippytrip').hover(function(){ 
    var offset = $(this).offset(); 
    console.log(offset) 
    var width = $(this).outerWidth(); 
     var tooltipId = this.hash; 
     $('#tooltip-container').empty().load 
('tooltips.html ' + tooltipId).show(); 
     $('#tooltip-container').css({top:offset.top, 
left:offset.left + width + 10}).show(); 
    }, function(){ 
     $('#tooltip-container').hide(); 
}); 
    }); 

我認爲部分是罪魁禍首就是:

var tooltipId = this.hash; 

我已經嘗試了各種各樣的東西,基本上我需要改變它:

<a href="#tip1" class="tippytrip">Show Tip 1 - again</a> 

到:

<span class="tippytrip" rel="tip1">Show Tip 1</span> 

非常感謝

+1

我認爲一個鏈接將實際上被罰款,但你只需將其更改爲'無功tooltipId =「# '+ $(this).attr('rel');',儘管'rel'不是'span'標籤的有效屬性。 – 2012-02-02 12:37:03

回答

3
var tooltipId = $(this).attr("rel"); 
+0

工作正常!謝謝,我會在7分鐘內接受,當stackoverflow讓我!大聲笑 – user1145334 2012-02-02 12:41:57

1

更改它讀取:

var tooltipId = $(this).attr('rel'); 
1

而不是使用rel,我會使用data屬性即

<span class="tippytrip" data-tooltip="tip1">Show Tip 1</span>

然後,作爲atornblad所暗示的,var tooltipId線改爲

var tooltipId = $(this).data("tooltip");

相關問題