2010-07-07 70 views

回答

1

這不是很漂亮,但我很快就破解了一起:

$(".slidetabs a").mouseover(function() { 
    // clear styles from the other elements 
    $(".headline-list a").removeClass("current"); 
    // find the corresponding headline and highlight it 
    $(".headline-list a:eq(" + $(this).index() + ")").addClass("current"); 
}); 

希望它能幫助。另外,你真的應該把所有的DOM引用代碼包裝在你傳遞給document.ready()函數的處理程序中,這將確保它只在DOM完全生成後才能運行。如果你不這樣做,那麼當你試圖查詢它們時,你的腳本中引用的元素(例如「.slidetabs」)是否實際上存在於頁面中,這種說法有點兒諷刺意味。下面是使用的document.ready()與您的代碼示例:

$(document).ready(function() { 
    // What is $(document).ready ? See: http://flowplayer.org/tools/documentation/basics.html#document_ready 

    var api = $(".slidetabs").tabs(".images > div",{api: true}); 

    api.onClick(function (tabIndex) { 
     console.log(tabIndex); 
     if (tabIndex === 0) { 
     $("headline-list > li > a.current").hide(); 
     } 
    }); 

    // removed the shorthand $(function() { }); part 
    // since the whole thing is inside the more readable document.ready handler now 

    $(".slidetabs,.headline-list").tabs(".images > div", {event:'mouseover'},{ 

     // enable "cross-fading" effect 
     effect: 'fade', 
     fadeOutSpeed: "slow", 

     // start from the beginning after the last tab 
     rotate: true 

    }).slideshow(); 
}); 
0

添加一個ID給每個「標籤」(被顯示爲點),你就可以找到相應的標題元素從它。從那裏,它只是確保它是唯一一個與類current

<!-- the tabs --> 
<div class="slidetabs"> 
    <a id="tab_0" class="current" href="#"></a> 
    <a id="tab_1" href="#"></a> 
    <a id="tab_2" href="#"></a> 
</div> 

... 

$(".slidetabs a").mouseover(function() { 
    $(".headline-list li a").removeClass("current"); 
    var id = $(this).attr("id").substr(4); 
    $(".headline_"+id).addClass("current"); 
}) 

你可能想使headline_X類IDS - 除非其實也希望讓每個多重,但他們似乎更喜歡獨特的標識符,其行爲相同的元素的類。