JQuery 切换按钮和手风琴问题

发布于 2024-09-14 13:30:06 字数 1221 浏览 2 评论 0原文

我有一个“菜单”btn,应该滑动打开一个带有“手风琴”菜单的 div。

当我为包含手风琴的 div 添加值 hide() (在 JS 中)或“hidden”(在 CSS 中)时,手风琴将停止正常工作。使用菜单 btn 打开带有手风琴的 div 后,单击手风琴部分时,它不会查看其中的所有内容。

我用手风琴隐藏 div 的原因是它应该关闭,直到您按下菜单 btn。

手风琴代码:

<script type="text/javascript">
    $(function() {
    //  $('.effect').hide();
        $("#moduleMenu1, #moduleMenu2").accordion({collapsible: true, active: false});
    });
</script>

菜单 btn 代码:

<script type="text/javascript">
    $(function() {
    $(".moduleMenuBtn").click(function() {
        var effect = $('slide').val();
        var options = {};
        $(this).parent().next(".effect").toggle(effect,options,500);
        return false;
    });
});
</script>

请注意,菜单 btn 的脚本不会用手风琴“滑动”打开 div,它只是弹出而没有“滑动”动画?

超文本标记语言

<div class="effect">
                    <div id="moduleMenu1">
                        <h3><a href="#">Section1</a></h3>
                        <div>
                          <p>Some Content</p>
                        </div>
                    </div>
                  </div>

I have a "Menu" btn that should slide-open a div with an "accordion" menu in it.

When I add the value hide() (in JS) or "hidden" (in CSS) for the div that contains the accordion, the accordion stops working properly. It doesn't view all the content in it when you click on an accordion section, after opening the div with the accordion with the Menu btn.

The reason I'm hiding the div with the accordion, is that it should be closed until you press the Menu btn.

Code for Accordion:

<script type="text/javascript">
    $(function() {
    //  $('.effect').hide();
        $("#moduleMenu1, #moduleMenu2").accordion({collapsible: true, active: false});
    });
</script>

Code for Menu btn:

<script type="text/javascript">
    $(function() {
    $(".moduleMenuBtn").click(function() {
        var effect = $('slide').val();
        var options = {};
        $(this).parent().next(".effect").toggle(effect,options,500);
        return false;
    });
});
</script>

Notice that the script for the Menu btn doesn't "slide" open the div with the accordion, it just popps out without the "slide" animation?

HTML

<div class="effect">
                    <div id="moduleMenu1">
                        <h3><a href="#">Section1</a></h3>
                        <div>
                          <p>Some Content</p>
                        </div>
                    </div>
                  </div>

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

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

发布评论

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

评论(1

驱逐舰岛风号 2024-09-21 13:30:06

你的第一部分是正确的,

$("#moduleMenu1, #moduleMenu2").accordion({
      collapsible: true, active: false
});

如果你运行它,它显示所有部分都允许关闭,并且没有一个部分打开。

问题是您触发了菜单按钮上的单击事件,该事件打开了 #moduleMenu1 open 的内容。

实际上还

$('.effect').hide();

隐藏了整个菜单和内容部分,而不是您想要的。

You have the first part correct

$("#moduleMenu1, #moduleMenu2").accordion({
      collapsible: true, active: false
});

If you run it with just that it shows with all sections allowed to be closed and none of them open.

The problem is that you fire the click event on the menu button which opens the content for #moduleMenu1 open.

Also

$('.effect').hide();

Actually hides the entire menu and content section, not what you want.

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