独立滑动切换链接

发布于 2025-01-02 07:42:40 字数 430 浏览 2 评论 0原文

一直试图让 SlideToggle 在已打开的情况下关闭,或者在已打开的情况下不重新打开。查遍了这个功能,但没有结果。任何帮助将不胜感激!

jQuery

   <script>
$(document).ready(function() {
  $(".shareLink").click(function(){
$(".hideShare").hide();
  $("#"+$(this).attr('id')+'Box').slideToggle();
  return false;
  });

});
</script>

这里有一个链接 http://digitalzu.net/jquery.html

Been trying to get slideToggle to close if already opened aka not reopen if already open. Searched all over for this function but to no avail. Any help would be much appreciated!

jQuery

   <script>
$(document).ready(function() {
  $(".shareLink").click(function(){
$(".hideShare").hide();
  $("#"+$(this).attr('id')+'Box').slideToggle();
  return false;
  });

});
</script>

heres a link to it
http://digitalzu.net/jquery.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

咋地 2025-01-09 07:42:40

它不起作用,因为您隐藏了所有 hideShare 元素,其中也包括当前框,因此它只是切换。

试试这个,它只会隐藏它的兄弟

 $(".shareLink").unbind().click(function(){
       $("#"+$(this).attr('id')+'Box')
       .siblings('.hideShare')
       .slideUp()
       .end()
       .slideToggle();

       return false;
  });

演示

Its not working because you are hiding all the hideShare elements which includes the current box also so it just toggles.

Try this, it will only hide its siblings.

 $(".shareLink").unbind().click(function(){
       $("#"+$(this).attr('id')+'Box')
       .siblings('.hideShare')
       .slideUp()
       .end()
       .slideToggle();

       return false;
  });

Demo

最佳男配角 2025-01-09 07:42:40
var $el = $("#"+$(this).attr('id')+'Box');

if($el.is(":hidden")){
    $(".hideShare").hide();
    $el.slideDown();
}

您隐藏了所有内容,然后向下滑动一个元素。问题是即使该元素已经可见,您也会这样做。相反,请确保它尚未可见,如果可见,则不执行任何操作。

var $el = $("#"+$(this).attr('id')+'Box');

if($el.is(":hidden")){
    $(".hideShare").hide();
    $el.slideDown();
}

You're hiding everything and then sliding down the one element. The problem is that you are doing this even if the element is already visible. Instead, make sure that it is not already visible, if it is, do nothing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文