[英]Expand/Collapse Issue
I want to expand/collapse only one container at a time. 我想一次扩展/折叠一个容器。 When I click on first container second container should collapse and when second container expanded, first container should collapse automatically.
当我点击第一个容器时,第二个容器应该折叠,当第二个容器展开时,第一个容器应该自动折叠。 Following is the Fiddle.
以下是小提琴。 Please guide... Thanks
请指导......谢谢
http://jsfiddle.net/awaises/eK8X5/1138/ http://jsfiddle.net/awaises/eK8X5/1138/
jQuery
$(".header").click(function () {
$header = $(this);
$content = $header.next();
$content.slideToggle(500, function () {
$header.text(function () {
return $content.is(":visible") ? "Collapse" : "Expand";
});
});
});
You can add this line to your click handler: 您可以将此行添加到您的点击处理程序:
$(".header").not(this).text('Expand').next().slideUp();
Use this 用这个
$(".content").not($content).slideUp();
before you call the slideToggle function and ofcourse dont forget to update the text of the header 在调用slideToggle函数之前,不要忘记更新标题的文本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.