首页 > 解决方案 > 每次单击togle-slide时如何滑动div并显示不同的内容?

问题描述

每次单击工具滑动按钮时,我都会尝试在 div 之间切换。每次单击切换按钮时,另一个按钮也应隐藏/显示。

html代码:

<div id="divParticipants">
click 'on' to hide the button and show the second content 
</div>
<div id="divPackage" style='display:none'>
click 'off' to hide the button and hide first content 
</div>

<button type="button" id='add-new'>
another button 
</button>

javascript代码:

$(function () {
        $('#package-toogle').change(function () {
            $('#divParticipants').hide("slide", { direction: "right" }, 400, function () {
               $('#add-new').hide(); 
            });

            $('#divPackage').show("slide", { direction: "left" }, 400, function () {
                $('#add-new').show();
            });
        })
    });

我花了半个小时试图让它工作,但无法让它工作。如果您能展示如何做到这一点,我将不胜感激。这是jsfiddle链接。

https://jsfiddle.net/p9qarjg0/36/

标签: javascriptjqueryhtmlswitch-statementtoggle

解决方案


尝试使用切换。

      $(function () {
        $('#package-toogle').on('change', function () {
            $('#divParticipants').toggle("slide", { direction: "right" }, 400, function () {
            });

            $('#divPackage').toggle("slide", { direction: "left" }, 400, function () {
            });
          $('#add-new').toggle();
        })
    });

推荐阅读