Jquery Slidetoggle各个功能(打开/关闭)

发布于 2024-12-17 08:56:36 字数 668 浏览 4 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

娇女薄笑 2024-12-24 08:56:36

试试这个,它将找到 id 以 slickbox 开头的所有元素并将其向上滑动。

$('a.clickdown').each(function() {
    var $this = $(this);
    var index = $this.attr('id').match(/(\d+)$/, '');
    var number = parseInt(index[1]);
    $this.click(function() {
        $('[id^=slickbox]').slideUp(); // This does the magic.
        $('#slickbox' + number).stop(true, true).slideToggle(400);
        $this.toggleClass('opened').blur();
        return false;
    });
});

Try this, which will find all elements which id start with slickbox and slide those up.

$('a.clickdown').each(function() {
    var $this = $(this);
    var index = $this.attr('id').match(/(\d+)$/, '');
    var number = parseInt(index[1]);
    $this.click(function() {
        $('[id^=slickbox]').slideUp(); // This does the magic.
        $('#slickbox' + number).stop(true, true).slideToggle(400);
        $this.toggleClass('opened').blur();
        return false;
    });
});
遮云壑 2024-12-24 08:56:36

为每个要隐藏的链接添加一个 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();

我的痛♀有谁懂 2024-12-24 08:56:36

我认为您正在寻找 jquery Accordionhttp://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.

§对你不离不弃 2024-12-24 08:56:36

添加对 #slickbox 的父级(我们将其称为 slick_parent)和所有子 div slideUp 的调用,然后向所需的框滑动:

$this.click(function() {
    $('#slick_parent > div').slideUp();
    $('#slickbox' + number).slideToggle(400);
    $this.toggleClass('opened').blur();
    return false;
});

Add a call to #slickbox's parent (lets call it slick_parent) and slideUp all child divs, and then slideDown the desired box :

$this.click(function() {
    $('#slick_parent > div').slideUp();
    $('#slickbox' + number).slideToggle(400);
    $this.toggleClass('opened').blur();
    return false;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文