gpt4 book ai didi

jQuery slideToggle 重叠的 div 集

转载 作者:太空宇宙 更新时间:2023-11-04 11:31:52 25 4
gpt4 key购买 nike

我有两列,A 和 B。有些A开多个B。A 将切换它的 B 元素 - 但是单击包含已打开的 B 的 A 开始混淆切换。

我想让每个 A 打开它的 B,如果其中一个或多个 B 已经打开,则不要将其关闭。再次单击 A 将关闭其各自的 B。

我想我真的很接近了——我看这个方式太久了:

<style>
#aItems li, h3.bTitle{ cursor: pointer;}

/* shell - structure */
#wrap { width:870px; margin:0 auto;}
#leftcolumn { width: 250px; float: left; margin-right: 30px; }
#rightcolumn { width: 590px; float: right;}

/* Indicators */
.activeAye{color:blue;}
.beeOpen{color:red;}

/* Start Hidden */
.bItem { display: none;}
</style>
<script>
jQuery( document ).ready(function( $ ) {
/* Column A*/
/* Click Item A -> Expand Relevant B's */
$('.aItem').click(function(){
$(this).toggleClass('activeAye');
$('.aItem').not(this).removeClass('activeAye');

/*
- This will close all so that each Group Toggle Works
- But Breaks the option to close toggled B Group by clicking the opening A
*/
// $('.bItem').slideUp("fast");

// Define target B's
var beeTarget = $(this).data('bdesc');

// Toggle Targets
$(beeTarget).slideToggle("medium").prev('h3').toggleClass('beeOpen');
});
/* Column B */
$(".bTitle").click(function(){
// toggle bItem div open/close
$(this).next('.bItem').slideToggle("medium");
});
});
</script>

<div id="wrap">
<h1>Overlapping Div Sets</h1>
<ul>
<li>Item in Column A toggle open/close relevant descriptions on the items in column B.</li>
<li>Clicking on another Item in A should:
<ul>
<li>Close non-relevant B Items</li>
<li>Keep open any relevant ones</li>
<li>Open any that are closed</li>
</ul>
</li>
<li>Clicking any Item in B directly will toggle it open/closed - with no impact to A->B functionality</li>
</ul>
<div id="leftcolumn">
<h4>Column A</h4>
<ul id="aItems">
<li class="aItem ayeOne" data-bdesc=".beeOne"><h3>A One</h3>Toggle B1</li>
<li class="aItem ayeTwo" data-bdesc=".beeOne, .beeTwo"><h3>A Two</h3>Toggle B1 and B2</li>
<li class="aItem ayeThree" data-bdesc=".beeOne, .beeThree"><h3>A Three</h3>Toggle B1 and B3</li>
<li class="aItem ayeFour" data-bdesc=".beeFour"><h3>A Four</h3>Toggle B4</li>
<li class="aItem ayeFive" data-bdesc=".beeFive"><h3>A Five</h3>Toggle B5</li>
<li class="aItem ayeSix" data-bdesc=".beeSix"><h3>A Six</h3>Toggle B6</li>
</ul>
</div><!-- /#leftcolumn -->
<div id="rightcolumn">
<h4>Column B</h4>
<h3 class="bTitle">B One</h3>
<div class="bItem beeOne">Nam at tortor in tellus interdum sagittis.</div>
<h3 class="bTitle">B Two</h3>
<div class="bItem beeTwo">In hac habitasse platea dictumst.</div>
<h3 class="bTitle">B Three</h3>
<div class="bItem beeThree">Cras dapibus.</div>
<h3 class="bTitle">B Four</h3>
<div class="bItem beeFour">Suspendisse eu ligula.</div>
<h3 class="bTitle">B Five</h3>
<div class="bItem beeFive">Sed hendrerit.</div>
<h3 class="bTitle">B Six</h3>
<div class="bItem beeSix">Aenean imperdiet.</div>
</div><!-- /#rightcolumn -->
</div><!-- /#wrap -->

http://jsfiddle.net/dwcouch/6p65ea2g/

最佳答案

请看一下:

/* Column A*/
/* Click Item A -> Expand Relevant B's */
$('.aItem').click(function(){

$(this).addClass('activeAye');
$('.aItem').not(this).removeClass('activeAye');
$('.bItem').prev('h3').removeClass('beeOpen');
/*
- This will close all so that each Group Toggle Works
- But Breaks the option to close toggled B Group by clicking the opening A
*/
// $('.bItem').slideUp("fast");

// Define target B's
var beeTarget = $(this).data('bdesc');
$('.bItem').not( $(beeTarget)).slideUp();
// Toggle Targets
$(beeTarget).slideDown("medium").prev('h3').addClass('beeOpen');

});
/* Column B */
$(".bTitle").click(function(){
// toggle bItem div open/close
$(this).next('.bItem').slideToggle("medium");
});

http://jsfiddle.net/6p65ea2g/1/

关于jQuery slideToggle 重叠的 div 集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31974601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com