我正在使用这个 jquery Show/hide 插件http://papermashup.com/jquery-show-hide-plugin/
我打算在单击页面上的任何链接时关闭以前的 div ,但是当我单击新链接时,我以前的 div 保持打开状态。
我的html
<div id="slidingDiv_2" class"toggleDiv"><!-- Conteúdo do menu 1 -->
<div class="opmenu">
<table>
<tr>
<td>
<ul>
<li><a href="#!">CENTROS DE ACTIVIDADES NOS TEMPOS LIVRES</a></li>
<li><a href="#!">SERVIÇO DE ATENDIMENTO E ACOMPANHAMENTO SOCIAL</a></li>
<li><a href="#!">CENTRO COMUNITÁRIO</a></li>
<li><a href="#!">APARTAMENTO PARA A AUTONOMIA DE VIDA</a></li>
</ul>
</td>
</tr>
</table>
</div>
</div>
我的链接:
<li class="items_menu"><a href="#" class="show_hide" rel="#slidingDiv">A INSTITUIÇÃO</a></li>
我的js:
(function ($) {
$.fn.showHide = function (options) {
//default vars for the plugin
var defaults = {
speed: 1000,
easing: 'easeInQuart',
changeText: 0,
showText: 'Mostrar',
hideText: 'Ocultar'
};
var options = $.extend(defaults, options);
$(this).click(function () {
$('.toggleDiv').slideUp(options.speed, options.easing);
// this var stores which button you've clicked
var toggleClick = $(this);
// this reads the rel attribute of the button to determine which div id to toggle
var toggleDiv = $(this).attr('rel');
// here we toggle show/hide the correct div at the right speed and using which easing effect
$(toggleDiv).slideToggle(options.speed, options.easing, function() {
// this only fires once the animation is completed
if(options.changeText==1){
$(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
}
});
return false;
});
};
})(jQuery);