使用 .slidetoggle 使 div 在页面加载时再次展开和折叠

发布于 2025-01-08 11:07:05 字数 728 浏览 2 评论 0原文

大家好,我有一个带有文本的 div 框,它是隐藏的,直到您单击按钮,然后它 .slideToggles 打开到其高度,然后当您再次单击时它会切换关闭。

现在我想做的是在页面加载时让框展开,然后再次折叠并停止(不是自动重复),以便人们看到隐藏的内容并单击按钮。有人可以帮忙吗?我不太喜欢 jQuery。

这就是我所拥有的。

        $(document).ready(function() {

            $("#page-information").hide();
                $(".info-tab").toggle(function() {
                    $(".info-tab").addClass("info-active");
                    }, function () {
                    $(this).removeClass("info-active");
                }); 
                $(".info-tab").click(function() {
                    $("#page-information").slideToggle('slow');
                });
            });

任何帮助将不胜感激。我以为你可以在一开始就连续进行两次滑动切换,但显然不行。

谢谢你们。

Hi guys i have a div box with text which is hidden until you click a button and then it .slideToggles open to its height and then when you click again it toggles closed.

Now what i would like to do is on page load for the box to expand and then collapse again and stop (not auto repeat ), so that people see that there is content hidden away and to click the button. Can anyone help with this?? I'm not big into jQuery.

Here's what i've got.

        $(document).ready(function() {

            $("#page-information").hide();
                $(".info-tab").toggle(function() {
                    $(".info-tab").addClass("info-active");
                    }, function () {
                    $(this).removeClass("info-active");
                }); 
                $(".info-tab").click(function() {
                    $("#page-information").slideToggle('slow');
                });
            });

Any help would be greatly appreciated. I thought you could just do two slidetoggles back to back at the beginning but obvioulsy not.

Thanks guys.

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

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

发布评论

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

评论(2

触ぅ动初心 2025-01-15 11:07:05

尝试一下:

$(document).ready(function() {

    $("#page-information").slideDown('slow', function(){
        setTimeout("$('#page-information').slideUp('slow');", 500);
    });
    $(".info-tab").toggle(function() {
        $(".info-tab").addClass("info-active");
        }, function () {
        $(this).removeClass("info-active");
    });
    $(".info-tab").click(function() {
        $("#page-information").slideToggle('slow');
    });
});

它的工作示例: http://jsfiddle.net/ufomammut66/yRqqq/2/

Give this a go:

$(document).ready(function() {

    $("#page-information").slideDown('slow', function(){
        setTimeout("$('#page-information').slideUp('slow');", 500);
    });
    $(".info-tab").toggle(function() {
        $(".info-tab").addClass("info-active");
        }, function () {
        $(this).removeClass("info-active");
    });
    $(".info-tab").click(function() {
        $("#page-information").slideToggle('slow');
    });
});

Example of it working: http://jsfiddle.net/ufomammut66/yRqqq/2/

む无字情书 2025-01-15 11:07:05

也许是这个?

$(document).ready(function() {

   $(".info-tab").toggle(function() {
       $(".info-tab").addClass("info-active");}
   });

   setTimeout(function(){
       $(".info-tab").toggle(function() {
          $(this).removeClass("info-active");
          $("#page-information").slideToggle('slow');
       });
    }, 1000);



        $("#page-information").hide();
            $(".info-tab").toggle(function() {
                $(".info-tab").addClass("info-active");
                }, function () {
                $(this).removeClass("info-active");
            }); 
            $(".info-tab").click(function() {
                $("#page-information").slideToggle('slow');
            });
        });

Maybe this?

$(document).ready(function() {

   $(".info-tab").toggle(function() {
       $(".info-tab").addClass("info-active");}
   });

   setTimeout(function(){
       $(".info-tab").toggle(function() {
          $(this).removeClass("info-active");
          $("#page-information").slideToggle('slow');
       });
    }, 1000);



        $("#page-information").hide();
            $(".info-tab").toggle(function() {
                $(".info-tab").addClass("info-active");
                }, function () {
                $(this).removeClass("info-active");
            }); 
            $(".info-tab").click(function() {
                $("#page-information").slideToggle('slow');
            });
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文