2014-10-06 113 views
0

我必須執行隱藏操作並在單擊兄弟上的按鈕時顯示div。顯示/隱藏懸停的特定部分並隱藏鼠標移出的div

但是,操作也發生在其他divs中。你可以在下面的鏈接中看到它。

這是小提琴(http://jsfiddle.net/NKC2j/1767/)。

腳本我用,

$(".panel").hide(); 
    $(".two").hide(); 

    $(document).ready(function(){ 
     $(".slidedown").click(function(){ 
     $(".panel").slideDown("slow"); 
     $(".one").hide(); 
     $(".two").show(); 
     }); 
     $(".slideup").click(function(){ 
     $(".panel").slideUp("slow"); 
     $(".two").hide(); 
     $(".one").show(); 
     }); 
    }); 

我需要的是輸出,

  1. 操作必須是單獨的盒子,而不是所有的箱子在同一時間。 (即,當單擊添加按鈕而不是僅一個框時,橙色框顯示在所有黑色框中)。

  2. 當鼠標離開黑色框時,類(一)隱藏(中間文字)顯示。但是,在點擊添加並取消並鼠標移出之後,類(一)不會隱藏。

+0

首先找到封閉產品爲當前按鈕, 變量$容器= $標籤。最接近( 'SEP-PROD。'); 然後對其下的元素進行操作 var $ contents = $ container.find('[data-content]'); 這可以幫助你。 – ArunGeorge 2014-10-06 07:50:19

+0

你可以讓它在我製作的小提琴中工作嗎? – ARUN 2014-10-06 07:53:59

+0

我已經更新了你的小提琴。請檢查。如果小提琴沒有正確反映,請告訴我。 – ArunGeorge 2014-10-06 08:08:21

回答

0

我做了一個工作搗鼓你: http://jsfiddle.net/NKC2j/1780/

$(".sep-prod").each(function(){ 
    $(".one,.two,.panel").hide(); 
     $(this).hover(function(){ 
      $(this).find(".middle-desc").hide(); 
      $(this).find(".one").show(); 
     },function(){ 
      $(this).find(".one,.two,.panel").hide(); 
      $(this).find(".middle-desc").show(); 
    }); 
}); 

$(".slidedown").click(function(){ 
     $(this).parents().eq(1).find(".one").hide(); 
     $(this).parents().eq(1).find(".two").show(); 
     $(this).parents().eq(1).children(".panel").slideDown("slow"); 
}); 

通過使用jQuery您可以將隱藏/每個功能僅顯示當前的懸停的元素。 在點擊功能中,您可以通過$(this).parents().eq(1)兩位父母向上查找dom,然後查找該父級的子級「.panel」。

$(this).parents().eq(1).find(".one").hide();

如果你想後懸停了.panel到效果基本show,那麼這是可能的: http://jsfiddle.net/NKC2j/1781/

+0

http://jsfiddle.net/NKC2j/1782/你剛剛錯過了隱藏部分。 但是,這是我需要的。 – ARUN 2014-10-06 08:36:12

0

您需要的是識別給定產品的容器。像這樣的東西。

$(".slidedown").click(function(event){ 
     var $productContainer = $(event.target).closest('.sep-prod'); 
    $productContainer.find(".panel").slideDown("slow"); 
    $productContainer.find(".one").hide(); 
    $productContainer.find(".two").show(); 
    }); 
    $(".slideup").click(function(){ 
     var $productContainer = $(event.target).closest('.sep-prod'); 
    $productContainer.find(".panel").slideUp("slow"); 
    $productContainer.find(".two").hide(); 
    $productContainer.find(".one").show(); 
    }); 
}); 
+0

感謝您的努力,Bro! jsfiddle.net/NKC2j/1782是我需要的解決方案。 – ARUN 2014-10-06 08:37:23