【问题标题】:Jquery UI slideUp and slideDownJquery UI slideUp和slideDown
【发布时间】:2012-01-25 21:58:30
【问题描述】:

我正忙着通过单击按钮来显示和隐藏一些框。它运行良好,但我第一次想要隐藏一个框时必须单击 2 次?

这是我的 JS 代码:

$(function() {
    $('.title .hide').showContent();
});

$.fn.showContent = function() {
    return this.each(function() {
        var box = $(this);
        var content = $(this).parent().next('.content');

        box.toggle(function() {
            content.slideDown(400);
        }, function() {
            content.slideUp(400);
        });

    });
}; 

还有 HTML

<div class="box">
    <div class="title">
        Title
        <span class="hide"></span>
    </div>
    <div class="content">Content</div>
</div>

这是为什么?有人可以帮助我吗?

这是一个演示:http://jsfiddle.net/wq7PF/(点击黑色按钮。当你第一次点击时它什么也不做,但第二次点击时内容会崩溃。)

【问题讨论】:

  • @Maanstraat 你在 HTML 中提到的按钮在哪里?
  • 按钮是带有隐藏类的span:
  • 我做了一个 JSFiddle 到:jsfiddle.net/wq7PF

标签: jquery jquery-ui toggle slidedown slideup


【解决方案1】:

反转你的功能

box.toggle(function() {
  content.slideUp(400);
}, function() {
  content.slideDown(400);
});

【讨论】:

    猜你喜欢
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多