3
votes

L'accordéon Bootstrap se cache quand un autre s'ouvre

J'essaye de faire de l'accordéon quand l'un est ouvert que l'autre sera fermé. voici mon js:

 $(".uv-accordinaton-list").on( "click", function() {
   $(this).next().slideToggle(200);
   $(this).find(">:first-child");
   if($(this).find(">:first-child").text() == "+") {
      $(this).find(">:first-child").text("-");
      $(this).find("h2").addClass("hilighted");
   } else {
   $(this).find(">:first-child").text("+");
   $(this).find("h2").removeClass("hilighted");
 }

Le lien en direct est: https: / /codepen.io/sifulislam/pen/vWxGLK

merci d'avance.


2 commentaires

Copie possible de Twitter Bootstrap plusieurs accordéons mais un seul panneau ouvert à la fois


Ce n'est pas pareil. J'utilise Plus minus sur un panneau sur js.


3 Réponses :


2
votes

Vous pourriez peut-être essayer ceci

  $(".uv-accordinaton-list").on( "click", function() {
    $(".uv-accordinaton-list>:first-child").text("+");
    $(".uv-accordinaton-list h2").removeClass("hilighted");
    $(".uv-accordition-detail").slideUp();
    if($(this).find(">:first-child").text() == "+") {
     $(this).next().slideToggle(200);
       $(this).find(">:first-child").text("-");
      $(this).find("h2").addClass("hilighted");
    }
  });


0 commentaires

1
votes

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<div class="container demo">

	
	<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

		<div class="panel panel-default">
			<div class="panel-heading" role="tab" id="headingOne">
				<h4 class="panel-title">
					<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
						<i class="more-less glyphicon glyphicon-plus"></i>
						Collapsible Group Item #1
					</a>
				</h4>
			</div>
			<div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
				<div class="panel-body">
					  Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
				</div>
			</div>
		</div>

		<div class="panel panel-default">
			<div class="panel-heading" role="tab" id="headingTwo">
				<h4 class="panel-title">
					<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
						<i class="more-less glyphicon glyphicon-plus"></i>
						Collapsible Group Item #2
					</a>
				</h4>
			</div>
			<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
				<div class="panel-body">
					Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
				</div>
			</div>
		</div>

		<div class="panel panel-default">
			<div class="panel-heading" role="tab" id="headingThree">
				<h4 class="panel-title">
					<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
						<i class="more-less glyphicon glyphicon-plus"></i>
						Collapsible Group Item #3
					</a>
				</h4>
			</div>
			<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
				<div class="panel-body">
					Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
				</div>
			</div>
		</div>

	</div><!-- panel-group -->
	
	
</div><!-- container -->
/*******************************
* ACCORDION WITH TOGGLE ICONS
* Does not work properly if "in" is added after "collapse".
*******************************/
	.panel-group .panel {
		border-radius: 0;
		box-shadow: none;
		border-color: #EEEEEE;
	}

	.panel-default > .panel-heading {
		padding: 0;
		border-radius: 0;
		color: #212121;
		background-color: #FAFAFA;
		border-color: #EEEEEE;
	}

	.panel-title {
		font-size: 14px;
	}

	.panel-title > a {
		display: block;
		padding: 15px;
		text-decoration: none;
	}

	.more-less {
		float: right;
		color: #212121;
	}

	.panel-default > .panel-heading + .panel-collapse > .panel-body {
		border-top-color: #EEEEEE;
	}

/* ----- v CAN BE DELETED v ----- */
body {
	background-color: #26a69a;
}

.demo {
	padding-top: 60px;
	padding-bottom: 110px;
}

.demo-footer {
	position: fixed;
	bottom: 0;
	width: 100%;
	padding: 15px;
	background-color: #212121;
	text-align: center;
}

.demo-footer > a {
	text-decoration: none;
	font-weight: bold;
	font-size: 14px;
	color: #fff;
}
    function toggleIcon(e) {
        $(e.target)
            .prev('.panel-heading')
            .find(".more-less")
            .toggleClass('glyphicon-plus glyphicon-minus');
    }
    $('.panel-group').on('hidden.bs.collapse', toggleIcon);
    $('.panel-group').on('shown.bs.collapse', toggleIcon);


1 commentaires

Bienvenue dans stackoverflow. En plus de fournir du code, pensez à ajouter un résumé de ce que vous avez changé et pourquoi cela fonctionne.



1
votes

Vérifiez le code ci-dessous:

$(".uv-accordinaton-list") . on("click", function() {
    $(this).closest("ul").find(".uv-accordition-detail").each(function() {
        if ($(this).css("display") == 'block') {
            $(this).slideUp(200);
            $(this).closest("li").find("h2").removeClass("hilighted");
            $(this).closest("li").find(".uv-right-arrow").text("+");
            return false;
        }
    });
    $(this).next().slideToggle(200);
    $(this).find(">:first-child");
    if ($(this).find(">:first-child").text() == "+") {
        $(this).find(">:first-child").text("-");
        $(this).find("h2").addClass("hilighted");
    } else {
        $(this).find(">:first-child").text("+");
        $(this).find("h2").removeClass("hilighted");
    }
});

Exemple de travail: https: / /codepen.io/rohitmittal/pen/WPdbbJ


0 commentaires