Bonjour à tous,
Je réalise un site pour mon association de roller hockey et je voudrais réaliser un effet accordéon pour mon site. La différence est qu'il ne s'agit pas là de menus mais d'éléments de contenu div.
Je me suis inspiré du tutoriel sur ce site (http://www.alsacreations.com/tuto/lire/602-Creer-un-menu-accordeon-avec-jQuery.html) que j'ai modifié pour l'adapter, tout fonctionne bien pour replier les éléments, mais pas pour les déplier.
http://nicolashumblot.fr/img/Accueil.htm
Voici le code html utile :
Et voici le Javascript modifié :
Je ne comprends pas très bien ce qui peut gêner. Au début, je pensais que c'était parce que dans le tutoriel la liste ul est dans l'élément de liste li, mais après coup, si l'élément n'a pas de mal à se fermer, pourquoi est-ce que ça coince quand il veut s'ouvrir ? Ça défie ma logique.
Si quelqu'un pouvait m'indiquer ce qui cloche, je lui en serait vraiment reconnaissant. Je ne connait pas très bien jQuery, je suis débutant et découvre un peu. Donc si ça se trouve c'est une erreur stupide et je m'en excuse...
Merci d'avance pour votre aide.
Modifié par Twitt (23 May 2012 - 12:39)
Je réalise un site pour mon association de roller hockey et je voudrais réaliser un effet accordéon pour mon site. La différence est qu'il ne s'agit pas là de menus mais d'éléments de contenu div.
Je me suis inspiré du tutoriel sur ce site (http://www.alsacreations.com/tuto/lire/602-Creer-un-menu-accordeon-avec-jQuery.html) que j'ai modifié pour l'adapter, tout fonctionne bien pour replier les éléments, mais pas pour les déplier.

http://nicolashumblot.fr/img/Accueil.htm
Voici le code html utile :
<div id="recap_equipe">
<h3 id="titre_mod_nextMatches" class="toggleSubMenu"><a href="" title="Afficher le sous-menu">Prochain match</a></h3>
<div id="contenu_mod_nextMatches" class="subMenu">
<p class="noGamePlanned">Aucun match n'est programmé pour le moment.</p>
</div>
<h3 id="titre_mod_results" class="toggleSubMenu"><a href="" title="Afficher le sous-menu">Dernier match</a></h3>
<div id="contenu_mod_results" class="subMenu" style="display: none; ">
<div class="emblem_thome"><p><img src="Accueil_files/bl133647.jpg" width="148"></p></div>
<div class="emblem_taway"><p><img src="Accueil_files/bl133648.jpg" width="148"></p></div>
<div class="team_thome"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=1&sid=1&Itemid=">Dijon</a> </div>
<div class="team_taway"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=4&sid=1&Itemid=">Lons-le-Saunier</a> </div>
<div class="match_date">
<p>25/03/2012 <br> 14:00</p>
</div>
<div class="hometeam_score">
<p><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=view_match&id=56&Itemid=">7</a></p>
</div>
<div class="awayteam_score">
<p><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=view_match&id=56&Itemid=">5</a></p>
</div>
</div>
<h3 id="titre_mod_table" class="toggleSubMenu"><a href="" title="Afficher le sous-menu">Classement</a></h3>
<div id="contenu_mod_table" class="subMenu" style="display: none; ">
<h4 class="classement">Poule H</h4>
<table width="100%" class="tblview">
<tbody>
<tr>
<th width="20">№</th>
<th style="border-left:0px;"><div>Equipe</div></th>
<th>Joues</th>
<th>Points</th>
</tr>
<tr class="tblro1">
<td width="20">1</td>
<td width="80%" style="text-align:left;border-left:0px; padding:0px 10px;" nowrap="nowrap" class="blteamname"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=5&sid=1&Itemid=101">Lyon</a></td>
<td>14</td>
<td>31</td>
</tr>
<tr class="tblro0">
<td width="20">2</td>
<td width="80%" style="text-align:left;border-left:0px; padding:0px 10px;" nowrap="nowrap" class="blteamname"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=8&sid=1&Itemid=101">Mâcon</a></td>
<td>14</td>
<td>31</td>
</tr>
<tr class="tblro1">
<td width="20">3</td>
<td width="80%" style="text-align:left;border-left:0px; padding:0px 10px;" nowrap="nowrap" class="blteamname"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=4&sid=1&Itemid=101">Lons-le-Saunier</a></td>
<td>14</td>
<td>30</td>
</tr>
<tr class="tblro0">
<td width="20">4</td>
<td width="80%" style="text-align:left;border-left:0px; padding:0px 10px;" nowrap="nowrap" class="blteamname"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=7&sid=1&Itemid=101">Villard-Bonnot</a></td>
<td>14</td>
<td>28</td>
</tr>
<tr class="tblro1">
<td width="20">5</td>
<td width="80%" style="text-align:left;border-left:0px; padding:0px 10px;" nowrap="nowrap" class="blteamname"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=1&sid=1&Itemid=101">Dijon</a></td>
<td>14</td>
<td>22</td>
</tr>
<tr class="tblro0">
<td width="20">6</td>
<td width="80%" style="text-align:left;border-left:0px; padding:0px 10px;" nowrap="nowrap" class="blteamname"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=3&sid=1&Itemid=101">Chalon-sur-Saone</a></td>
<td>14</td>
<td>8</td>
</tr>
<tr class="tblro1">
<td width="20">7</td>
<td width="80%" style="text-align:left;border-left:0px; padding:0px 10px;" nowrap="nowrap" class="blteamname"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=6&sid=1&Itemid=101">Pontarlier</a></td>
<td>14</td>
<td>7</td>
</tr>
<tr class="tblro0">
<td width="20">8</td>
<td width="80%" style="text-align:left;border-left:0px; padding:0px 10px;" nowrap="nowrap" class="blteamname"><a href="http://localhost/cardinauxdijon/index.php?option=com_joomsport&task=team&tid=2&sid=1&Itemid=101">Besançon</a></td>
<td>14</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
</div>
Et voici le Javascript modifié :
<script type="text/javascript">
$(document).ready( function () {
// On cache les contenus :
$("#contenu_mod_results").hide();
$("#contenu_mod_table").hide();
// On s�lectionne tous les items de liste portant la classe "toggleSubMenu"
// et on remplace l'�l�ment span qu'ils contiennent par un lien :
$(".toggleSubMenu span").each( function () {
$(this).replaceWith('<a href="" title="Afficher le sous-menu">' + $(this).text() + '<\/a>') ;
} ) ;
//
//
////// A MODIFIER
//
//
// On modifie l'�v�nement "click" sur les liens dans les items de liste
// qui portent la classe "toggleSubMenu" :
$("h3.toggleSubMenu > a").click( function () {
// Si le sous-menu �tait d�j� ouvert, on le referme :
if ($(this).next(".subMenu:visible").length != 0) {
$(this).next(".subMenu").slideUp("normal");
}
// Si le sous-menu est cach�, on ferme les autres et on l'affiche :
else {
$(".subMenu").slideUp("normal");
$(this).next("div.subMenu").slideDown("normal");
}
// On emp�che le navigateur de suivre le lien :
return false;
});
} ) ;
</script>
Je ne comprends pas très bien ce qui peut gêner. Au début, je pensais que c'était parce que dans le tutoriel la liste ul est dans l'élément de liste li, mais après coup, si l'élément n'a pas de mal à se fermer, pourquoi est-ce que ça coince quand il veut s'ouvrir ? Ça défie ma logique.

Si quelqu'un pouvait m'indiquer ce qui cloche, je lui en serait vraiment reconnaissant. Je ne connait pas très bien jQuery, je suis débutant et découvre un peu. Donc si ça se trouve c'est une erreur stupide et je m'en excuse...
Merci d'avance pour votre aide.

Modifié par Twitt (23 May 2012 - 12:39)