如何在打开的面板中添加类?

时间:2010-10-25 22:51:47

标签: jquery panel addclass sliding

任何人都可以帮助我我在一个页面上使用了两个面板,我只想一次显示一个,所以我对js进行了调整,但它似乎没有添加类。有人可以帮忙吗?

    $(document).ready(function () {
        $("div.panel_buttonGal").click(function () {
            $("div#panelGal").animate({
                height: "150px"
            }).animate({
                height: "140px"
            }, "slow");
            $("div.panel_buttonGal").toggle();
            $("div#panelGal").addClass("open");
        });

        $("div#hide_buttonGal").click(function () {
            $("div#panelGal").animate({
                height: "0px"
            }, "slow");
            $("div#panelGal").removeClass("open");
        });
        $("div.panel_buttonAbt").click(function () {
            $("div#panelGal.open").animate({
                height: "0px"
            }, "fast");
        });
    });

HTML看起来像这样。

<pre><code>
<div id="panelGal" class="">
  <div class="panel_contents"> </div>
   <ul class="subnav">
            <li><a href="#">Engagements & Weddings</a></li>
            <li><a href="#">Maternity & Newborns</a></li>
            <li><a href="#">Seniors</a></li>
            <li><a href="#">Portraits</a></li>
            <li><a href="#">Photo Parties & Fundraisers</a></li>
            <li><a href="#">Special Events</a></li>
          </ul>
    </div>

    <div id="panelAbt" class="">
    <div class="panel_contents"> </div>
      <ul class="subnav">
            <li><a href="#">Bio</a></li>
            <li id="invest"><a href="#">Investment</a></li>
            <li><a href="#">Details (FAQ)</a></li>
            <li><a href="#">Testimonials</a></li>
            <li><a href="#">Vendors We Love</a></li>
          </ul>
    </div>

    <div id="nav">

        <div class="MainNav"><a href="#" class="rp">Home</a></div>
        <div class="MainNav"><a href="#" class="rp">About You</a></div>
        <div class="MainNav panel_buttonGal" style="display: visible;"><a class="rp">Galleries</a></div>
        <div class="MainNav panel_buttonGal" id="hide_buttonGal" style="display: none;"><a class="rp">Galleries</a></div>
        <div class="MainNav panel_buttonAbt" style="display: visible;"><a class="rp">About Us</a></div>
        <div class="MainNav panel_buttonAbt" id="hide_buttonAbt" style="display: none;"><a class="rp">About Us</a></div>
        <div class="MainNav"><a href="#" class="rp">The Latest</a></div>
        <div class="MainNav"><a href="#" class="rp">Proof & Shop</a></div>
        <div class="MainNav"><a href="#" class="rp">Contact Us</a></div>

    </div>

 </code></pre>

2 个答案:

答案 0 :(得分:0)

改为使用hide()show()

答案 1 :(得分:0)

使用slideUp()和slideDown(),而不是添加CSS类并使用animate():

$(document).ready(function () {
        $("div.panel_buttonGal").hide();  // initial state
        $("div.panel_buttonGal").click(function () {
            $("div#panelGal").slideDown("slow");
            $("div.panel_buttonGal").toggle();
        });

        $("div#hide_buttonGal").click(function () {
            $("div#panelGal").slideUp("slow");
        });
        $("div.panel_buttonAbt").click(function () {
            $("div#panelGal").slideUp("fast");
        });
    });