2012-06-05 207 views
0

首先感謝您花時間幫助我完成此任務。jquery顯示/隱藏多個div切換

對不起,我的英語;-)

好吧,我給你一個鏈接到我的項目會更容易理解我的問題

http://lix.in/-c20b94

正如你可以在右側看到,你有社交小組。

我想用jquery打開每個面板(與最後一個提要)。在閱讀了一些帖子後,我能夠使其工作(我並不擅長jquery)。但我仍然有問題。

正如你可以注意到,當你點擊另一個按鈕(Facebook,YouTube的)面板關閉/打開等等,但按鈕本身保持活動的位置。它不會回到他的正常位置。我把它認爲由於切換問題

CODE:

$(".link1").click(function(){ 
    $("#twittercontent, #youtubehome").hide(); 
    $("#pz_fbplugin").toggle("fast"); 
    $(this).toggleClass("active"); 
    return false; 
    $(".link2, .link3").removeClass('active'); 
    $(".link1").addClass("active"); 
}); 

$(".link2").click(function(){ 
    $("#pz_fbplugin, #youtubehome").hide(); 
    $("#twittercontent").toggle("fast"); 
    $(this).toggleClass("active"); 
     return false; 
    $(".link1, .link3").removeClass("active"); 
    $(".link2").addClass("active"); 
}); 

$(".link3").click(function(){ 
    $("#pz_fbplugin, #twittercontent").hide(); 
    $("#youtubehome").toggle("fast"); 
    $(this).toggleClass("active"); 
    return false; 
    $(".link1, .link2").removeClass("active"); 
    $(".link3").addClass("active"); 
}); 

CSS:

a.facebook {width: 46px;position: fixed; right:0; height: 130px; top: 175px; margin-right: 0; background: url("socialrudyfacebook.png")no-repeat; z-index:51} 
a.facebook:hover{width: 129px} 
a.active.facebook{width: 129px} 

a.twitter{width: 46px; position: fixed; height: 130px;right: 0; top: 317px; margin-right: 0;z-index: 51;background: url("socialrudytwitter.png")no-repeat; a-index:51} 
a.twitter:hover{ width: 129px} 
a.active.twitter{ width: 129px} 

a.youtube{width: 46px;position: fixed; height: 130px; right: 0; top: 457px ;z-index: 150; background: url("socialrudyyoutube")no-repeat; a-index:51} 
a.youtube:hover{ width: 129px} 
a.active.youtube{ width: 129px} 

希望這enaugh你來幫我這。

+1

在所有情況下,您都有'return false;'在操作類之前,所以這些更改不會被執行。 –

回答

0

我覺得你的問題是return false。如果你刪除它或將它移下來,它應該工作。代替退貨,您還可以使用:

$(".link3").click(function(e){ 
    e.preventDefault(); 
    // your function and stuff 
}); 
+0

非常感謝您的一個小小的錯誤,誰有所作爲;-) – user1437654

0

當你return false其餘的代碼不會被執行。遠程它,它會起作用,或者只是簡單地做以下事情。

爲每個鏈接添加相同的類。像「標籤」一樣。

然後在每個.click,你有那裏只是打電話。

$('.tab').removeClass("active"); 

而當你點擊一個標籤,你會確保其餘的回到原來的狀態。

if ($(this).hasClass('active')) 
    $(this).removeClass('active'); 

該行添加到每個。點擊,它應該工作

+0

非常感謝您的回答;-) – user1437654

+0

爲您添加了一些代碼 –

0

return false移至功能末尾。這是必須的幫助。

+0

謝謝你的回答 – user1437654