0

我是 jQuery 的初学者。如何在向下滑动切换动画中更改我的 jQuery 按钮?

如果可以的话,我可以在这个 html 代码中使用 css 编码按钮吗?请帮助我使用完全编码的 html

<html>
<head>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
    $(document).ready(function() {
      $('.nav-toggle').click(function(){
        //get collapse content selector
        var collapse_content_selector = $(this).attr('href');                   

        //make the collapse content to be shown or hide
        var toggle_switch = $(this);
        $(collapse_content_selector).toggle(function(){
          if($(this).css('display')=='none'){
                            //change the button label to be 'Show'
            toggle_switch.html('Show');
          }else{
                            //change the button label to be 'Hide'
            toggle_switch.html('Hide');
          }
        });
      });

    }); 
    </script>
    <style> 
    .round-border {
        border: 1px solid #eee;
        border: 1px solid rgba(0, 0, 0, 0.05);
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        border-radius: 4px;
        padding: 10px;
        margin-bottom: 5px;
    }
    </style>
</head>
<body>
    <section class="round-border">

        <div>
            <button href="#collapse1" class="nav-toggle">Show</button>
        </div>
        <div id="collapse1" style="display:none">
            <p>Bla bla bla bla</p>
        </div>
    </section>
</body>
</html>
4

1 回答 1

0

you can use slideToggle function for showing and hiding div and for changing class usetoggleClass function demo you cant have href attr in button but you can use data attr

<button data-href="collapse1" class="nav-toggle">Show</button>
    $(".nav-toggle") .click(function(){
    $(this).toggleClass("active");
    var h =$(this).data('href');
    $("#"+h).slideToggle(300);
    return false;
    });
于 2013-07-26T05:52:14.510 回答