代码之家  ›  专栏  ›  技术社区  ›  user979331

jquery使用动画在高度之间切换

  •  0
  • user979331  · 技术社区  · 6 年前

    我尝试在一个类的两个高度之间切换并设置动画,我尝试了以下方法:

    $('.architectural-films').bind('click', function(){
                $(".section1").toggle(function(){
                                 $(".section1").animate({height:"500px"});
                            },function(){
                                 $(".section1").animate({height:"0px"});
                            });
                return false;
            });
    

    但它根本不起作用,没有动画,高度也不会改变。

    .section1{
    height: 0px;
    }
    

    这是html

    <section class="section1">
    
    <!--content here -->
    </section>
    

    1 回复  |  直到 6 年前
        1
  •  3
  •   לבני מלכה    6 年前

    .toggleClass

    $('.architectural-films').bind('click', function(){
        $(".section1").toggleClass("toggle");
    });
    .section1{
    background:red;
    height: 0px;
    transition: height 0.25s ease-out;
    }
    .toggle{
       height: 500px;
        transition: height 0.25s ease-in;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <section class="section1">
    
    <!--content here -->
    </section>
    <button class="architectural-films">click me</button>