2016-03-22 12 views
1

同じスペースに表示と非表示の3つのdivがあり、divを個別にクリックして表示/非表示にすると完全に正常に動作します。しかし、...最初のdivを開き、2番目のdivをクリックすると、自動的に2番目のdivを閉じることはありません...新しいdivがクリックされたときにdivが隠れないようにする

私が話していることを見るのが最も簡単だと思います下記のリンク:

http://www.voyagetestsite.co.za

私のHTMLを参照してください、私は...

jQuery(document).ready(function() { 
 
    jQuery(".menu-trigger").click(function() { 
 
    $(".menu-trigger").hide("scale") 
 
    jQuery(".test").slideToggle(900, function([complete]) { 
 
     jQuery(this).toggleClass(".test").css("display"); 
 
    }) 
 
    }); 
 
}); 
 
$("#hide").click(function() { 
 
    $("#bio-content").hide("slide"); 
 
    $("#hide").hide(); 
 
    $("#show").show(); 
 
}); 
 
$("#show").click(function() { 
 
    $("#bio-content").show("slide"); 
 
    $("#show").hide(); 
 
    $("#hide").show(); 
 
}); 
 
$("#hide2").click(function() { 
 
    $("#info-content").hide("slide"); 
 
    $("#hide2").hide(); 
 
    $("#show2").show(); 
 
}); 
 
$("#show2").click(function() { 
 
    $("#info-content").show("slide"); 
 
    $("#show2").hide(); 
 
    $("#hide2").show(); 
 
}); 
 
$("#hide3").click(function() { 
 
    $("#drums-content").hide("slide"); 
 
    $("#hide3").hide(); 
 
    $("#show3").show(); 
 
}); 
 
$("#show3").click(function() { 
 
    $("#drums-content").show("slide"); 
 
    $("#show3").hide(); 
 
    $("#hide3").show(); 
 
}); 
 
// Preload all the GIF. 
 
var image = []; 
 

 
$.each(gif, function(index) { 
 
    image[index] = new Image(); 
 
    image[index].src = gif[index]; 
 
}); 
 

 
function changeImage() { 
 
    var ima = document.getElementById("BSlate"); 
 
    if (ima.src.match('BIDSlate')) { 
 
    (ima.src = "img/BSlate.png"); 
 
    } else 
 
    (ima.src = "img/BIDSlate.gif"); 
 
}
#show, 
 

 
    #show2, 
 

 
    #show3 { 
 

 
     display: block; 
 

 
     background: none; 
 

 
     border: none; 
 

 
     font-family: anders; 
 

 
     font-size: 36px; 
 

 
     color: #ABD8C1; 
 

 
     outline: none; 
 

 
    } 
 

 
    #hide, 
 

 
    #hide2, 
 

 
    #hide3 { 
 

 
     display: none; 
 

 
     background: none; 
 

 
     border: none; 
 

 
     font-family: anders; 
 

 
     font-size: 36px; 
 

 
     color: #ABD8C1; 
 

 
     outline: none; 
 

 
    } 
 

 
    #bio-content { 
 

 
     background-color: rgba(0, 0, 0, 0.5); 
 

 
     width: 90%; 
 

 
     height: 400px; 
 

 
     display: none; 
 

 
     margin: 0 auto; 
 

 
     padding: 0; 
 

 
     position: relative; 
 

 
     z-index: 100; 
 

 
    } 
 

 
    #info-content { 
 

 
     height: 400px; 
 

 
     background-color: rgba(0, 0, 0, 0.5); 
 

 
     width: 90%; 
 

 
     display: none; 
 

 
     margin: 0 auto; 
 

 
     padding: 0; 
 

 
     position: relative; 
 

 
     z-index: 100; 
 

 
    } 
 

 
    #drums-content { 
 

 
     height: 400px; 
 

 
     background-color: rgba(0, 0, 0, 0.5); 
 

 
     width: 90%; 
 

 
     display: none; 
 

 
     margin: 0 auto; 
 

 
     margin-bottom: 50px; 
 

 
     padding: 0; 
 

 
     z-index: 100; 
 

 
     position: relative; 
 

 
    }
<!-------------------- MY HTML ---------------------------------> 
 

 
<ul> 
 
    <li> 
 
    <input type="button" value="Less Bio" id="hide" /> 
 
    <input type="button" value="Biography" id="show" /> 
 
    </li> 
 
    <li> 
 
    <input type="button" value="Less Info" id="hide2" /> 
 
    <input type="button" value="Info" id="show2" /> 
 
    </li> 
 
    <li> 
 
    <input type="button" value="Less Drums" id="hide3" /> 
 
    <input type="button" value="Drums" id="show3" /> 
 
    </li> 
 
</ul> 
 
<div id="bio-content"> 
 
    <div class="content-pic"> 
 
    <img src="img/biopic.png" /> 
 
    </div> 
 
    <div class="slide-content"> 
 
    <h1>Biography</h1> 
 
    <hr /> 
 
    <p>Lorem ipsum dolor</p> 
 
    </div> 
 
    <div id="info-content"> 
 
    <div class="content-pic"> 
 
     <img src="img/infopic.png" /> 
 
    </div> 
 
    <div class="slide-content"> 
 
     <h1>Information</h1> 
 
     <hr /> 
 
     <p>Lorem ipsum</p> 
 
    </div> 
 
    </div> 
 
    <div id="drums-content"> 
 
    <div class="content-pic"> 
 
     <img src="img/drumpic.png" /> 
 
    </div> 
 
    <div class="slide-content"> 
 
     <h1>Drums</h1> 
 
     <hr /> 
 
     <p>Lorem</p> 
 
    </div> 
 
    </div> 
 
</div> 
 
<span class="menu-trigger" onclick="changeImage()"> 
 
    <h1 class="menu-button">MENU</h1></span> 
 
<!-----------END MENU------------> 
 
</div> 
 
</div>

を不要なビットを取り出しました0
+0

アイデアは、すべてを隠し、1 –

答えて

0

コードを変更して機能させるようにしました。私はあなたが元に戻すことができるものをいくつか省略しました。

Fiddle

$(".link").click(function() { 
 

 
    if ($("#" + $(this).attr("desc")).css('display') != 'none') { 
 
    $(".description").hide(); 
 
    $(this).val($(this).val().substring(5)); 
 
    } else { 
 
    $(".description").hide(); 
 
    $(this).val("Less " + $(this).val()); 
 
    $("#" + $(this).attr("desc")).show("slide"); 
 
    } 
 
    var ob = this; 
 
    $(".link").each(function() { 
 
    if (!$(ob).is($(this)) && $(this).val().indexOf("Less") > -1) { 
 
     $(this).val($(this).val().substr(5)); 
 
    } 
 
    }); 
 
});
#show, 
 
#show2, 
 
#show3 { 
 
    display: block; 
 
    `enter code here` background: none; 
 
    border: none; 
 
    font-family: anders; 
 
    font-size: 36px; 
 
    color: #ABD8C1; 
 
    outline: none; 
 
} 
 

 
#hide, 
 
#hide2, 
 
#hide3 { 
 
    display: none; 
 
    background: none; 
 
    border: none; 
 
    font-family: anders; 
 
    font-size: 36px; 
 
    color: #ABD8C1; 
 
    outline: none; 
 
} 
 

 
#bio-content { 
 
    background-color: rgba(0, 0, 0, 0.5); 
 
    width: 90%; 
 
    height: 400px; 
 
    display: none; 
 
    margin: 0 auto; 
 
    padding: 0; 
 
    position: relative; 
 
    z-index: 100; 
 
} 
 

 
#info-content { 
 
    height: 400px; 
 
    background-color: rgba(0, 0, 0, 0.5); 
 
    width: 90%; 
 
    display: none; 
 
    margin: 0 auto; 
 
    padding: 0; 
 
    position: relative; 
 
    z-index: 100; 
 
} 
 

 
#drums-content { 
 
    height: 400px; 
 
    background-color: rgba(0, 0, 0, 0.5); 
 
    width: 90%; 
 
    display: none; 
 
    margin: 0 auto; 
 
    margin-bottom: 50px; 
 
    padding: 0; 
 
    z-index: 100; 
 
    position: relative; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<ul> 
 
    <li> 
 
    <input type="button" value="Biography" class="link" desc="bio-content"/> 
 
    </li> 
 
    <li> 
 
    <input type="button" value="Info" class="link" desc="info-content" /> 
 
    </li> 
 
    <li> 
 
    <input type="button" value="Drums" class="link" desc="drums-content" /> 
 
    </li> 
 
</ul> 
 

 
<div id="bio-content" class="description"> 
 
    <div class="content-pic"><img src="img/biopic.png" /></div> 
 
    <div class="slide-content"> 
 
    <h1>Biography</h1> 
 
    <hr /> 
 
    <p>Lorem ipsum dolor</p> 
 
    </div> 
 
    </div> 
 
    
 
    <div id="info-content" class="description"> 
 
    <div class="content-pic"><img src="img/infopic.png" /></div> 
 
    <div class="slide-content"> 
 
     <h1>Information</h1> 
 
     <hr /> 
 
     <p>Lorem ipsum</p> 
 
    </div> 
 
    </div> 
 
    
 
    <div id="drums-content" class="description"> 
 
    <div class="content-pic">hello</div> 
 
    <div class="slide-content"> 
 
     <h1>Drums</h1> 
 
     <hr /> 
 
     <p>Lorem</p> 
 
    </div> 
 
    </div> 
 

 

 
<!-----------END MENU------------>

+0

はあなたにHarshulに感謝を示すことです!あなたはここに私を救った!すべてが完璧に機能しているだけで、元のスタイルを入力要素に追加してブームを起こさなければなりませんでした。あなたは男です! –

+0

Ok ...メニュートリガーはSafariで動作しません。 –

1

Hmmm、それぞれのコンテンツdivにクラス(つまりclass = "content")を指定し、jQueryを使用して、現在のdivでないすべてのもの(たとえばドラムコンテンツ)を非表示にすることができます。

$(".content").not($("#drums-content")).hide(); 
0

class = "content-container"を3つのコンテンツdivに追加します。 3つの#show.click-functionsには、最初に$( "。content-container")を追加します。

関連する問題