簡體   English   中英

jQuery-激活一個切換按鈕將禁用另一個

[英]jQuery - Activating one toggle button disables the other

我在使用兩個jQuery切換按鈕時遇到問題。 它們用於移動導航按鈕:

(function($) {
    $(function() {
$('#mobile-nav-button').toggle(
    function() {
        $('#fullpage').animate({ left: 250 }, 'normal', function() {
            $('#mobile-nav-button').html('Close');{
            $('#social-nav-panel').hide();
        }
        });
    },
    function() {
        $('#fullpage').animate({ left: 0 }, 'normal', function() {
            $('#mobile-nav-button').html('Open');
        });
    }
);
$('#social-nav-button').toggle(
    function() {
        $('#fullpage').animate({ right: 250 }, 'normal', function() {
            $('#social-nav-button').html('Close');
        });
    },
    function() {
        $('#fullpage').animate({ right: 0 }, 'normal', function() {
            $('#social-nav-button').html('Open');
        });
    }
);
    });
})(jQuery);

靠自己,他們工作得很好。 第一個按鈕#mobile-nav-button每次都能完美運行。 第二個按鈕#social-nav-button也可以正常工作。 但是,如果選擇了#mobile-nav-button,那么#social-nav-button將停止工作(反之亦然,因為#mobule-nav-button始終可以工作,即使#social-nav -按鈕已被選中)。

我已經在堆棧溢出上看到很多類似的帖子(盡管不是同一問題),但是可悲的是,我的JS / jQuery知識遠不足以對我的問題進行任何修復。

任何幫助將不勝感激!

您可以查看我的示例: 切換按鈕顯示和隱藏

HTML:

<button type="button" id="mobile_bt">Mobile</button>
<button type="button" id="social_bt">Social</button>

使用jQuery的JS:

$('#mobile_bt').click(function() {
    var help= $(this);
  $('#social_bt').toggle('slow', function() {
    help.hide();
    $(this).show();
  });
});

$('#social_bt').click(function() {
    var help= $(this);
  $('#mobile_bt').toggle('slow', function() {
    help.hide();
    $(this).show();
  });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM