简体   繁体   English

jQuery Slidetoggle - 仅在一个框上显示/隐藏子菜单

[英]jQuery Slidetoggle - show/hide sub menu on one box only

I have created a page where I have showing multiple boxes, and each box have three vertical dots on top right corner, when you click on those three dots it will open sub menu, for which I have used slidetoggle and what I wanted is when user click on the dots from one box it should show at once place only but right now its showing on all boxes, the jQuery I have written is not working as expected. 我创建了一个页面,其中我显示了多个框,每个框在右上角有三个垂直点,当你点击这三个点时它会打开子菜单,为此我使用了slidetoggle和我想要的是当用户点击它应该立即显示的一个框中的点,但是现在它在所有框上显示,我写的jQuery没有按预期工作。

Here is the JSfiddle demo 这是JSfiddle演示

For slide toggle I have the following JQuery: 对于幻灯片切换,我有以下JQuery:

$('.popout_info > a').click(function () {
  $(".popout_info").next().slideToggle(200);
});

Can anyone please suggest how to handle this, if I assign ID to each DIV then in this case the boxes are going to be in unlimited numbers, may be something which can be handled dynamically? 任何人都可以建议如何处理这个,如果我为每个DIV分配ID,那么在这种情况下,框将是无限数量,可能是可以动态处理的东西?

Thanks in advance! 提前致谢!

You have to change your jQuery function to achieve that as: 你必须改变你的jQuery函数来实现它:

jQuery jQuery的

$('.popout_info > a').click(function() {
  $('.popout_list').slideUp(200);
  var nextPopup = $(this).parent(".popout_info").siblings('.popout_list');
  if (!($(nextPopup).is(':visible'))) {
    $(nextPopup).slideToggle(200);
  }
});

Here's your updated JSFiddle 这是你更新的JSFiddle

I have made some amendments to hide any other open popup if one popup opens to disallow redundancy. 如果一个弹出窗口打开以禁止冗余,我已经做了一些修改以隐藏任何其他打开的弹出窗口。

You are selecting every popup window. 您正在选择每个弹出窗口。 Try using : 尝试使用:

$('.popout_list').slideUp(200);
$(this).closest('.doctor_wrapper').find('.popout_list').slideToggle(400);

You can use the following code to achieve this. 您可以使用以下代码来实现此目的。

JS JS

$('.popout_info > a').click(function () {
    $(this).parent().parent().find(".popout_info").next().slideToggle(200);
  });

Or try this link https://jsfiddle.net/wo1b58wj/7/ 或尝试此链接https://jsfiddle.net/wo1b58wj/7/

I used: 我用了:

$('.popout_info > a').click(function () {
        $(this).parent().next().slideToggle(200);
  });

and it worked for me. 它对我有用。

Side note: it's hard to click on those three dots because the box resize on mouse enter/leave 旁注:很难点击这三个点,因为鼠标左键进入/离开时调整框大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM