Jquery Slidetoggle各个功能(打开/关闭)
我有以下 jquery 片段。它基本上是一个内容滑块,当我单击 id 为 slick-toggle1
的链接时,它将向下滑动匹配的内容 slickbox1
。与 slick-toggle2 相同 --> slickbox2 等等。
$('a.clickdown').each(function() {
var $this = $(this);
var index = $this.attr('id').match(/(\d+)$/, '');
var number = parseInt(index[1]);
$this.click(function() {
$('#slickbox' + number).slideToggle(400);
$this.toggleClass('opened').blur();
return false;
});
});
此时,当我单击各个链接时,相应的区域将堆叠起来。但是我想要实现的是:当我点击 slick-toggle2
时,它将显示 slickbox2
但隐藏其他内容(因此 slickbox1
& slickbox3
)。
I have the following piece of jquery. Which basically is a content slider, that when I click on a link with an id of slick-toggle1
it will slide down the matching content slickbox1
. The same with slick-toggle2 --> slickbox2
etcetc.
$('a.clickdown').each(function() {
var $this = $(this);
var index = $this.attr('id').match(/(\d+)$/, '');
var number = parseInt(index[1]);
$this.click(function() {
$('#slickbox' + number).slideToggle(400);
$this.toggleClass('opened').blur();
return false;
});
});
At the moment as I click through the individual links the corresponding areas will stack. However what I want to achieve is: when I click on say slick-toggle2
it will display slickbox2
but hide the others (so slickbox1
& slickbox3
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个,它将找到 id 以 slickbox 开头的所有元素并将其向上滑动。
Try this, which will find all elements which id start with slickbox and slide those up.
为每个要隐藏的链接添加一个
hidable
类,例如然后在 click 函数中执行
$( ".hidable").hide();
Add an
hidable
class to every link you want to hide, eg<a class="clickdown hidable">
then in the click function, do$(".hidable").hide();
我认为您正在寻找 jquery Accordion : http://docs.jquery .com/UI/Accordion 。这个 jQuery 插件会自动执行此操作。将您单击的幻灯片打开。并关闭其余部分。
I think that you are searching for the jquery accordion : http://docs.jquery.com/UI/Accordion . This jQuery plug-in does this automaticaly. Slides the one you click on open. And closes the rest.
添加对
#slickbox
的父级(我们将其称为slick_parent
)和所有子 divslideUp
的调用,然后向所需的框滑动:Add a call to
#slickbox
's parent (lets call itslick_parent
) andslideUp
all child divs, and then slideDown the desired box :