首页 > 解决方案 > 使用 .slideDown Jquery 函数后如何保持我的部分打开?

问题描述

我试图让这个功能向下滑动并保持向下,但它一直向上滑动。

 $('.call-to-action').on('click', function() {
        if ($('#new-tweet').is(':hidden')) {
          ($('#new-tweet').slideDown());
        } else {
          ($('#new-tweet').slideUp());
        }
      });
#new-tweet {
        display: flex;
        justify-content: center;
        flex-direction: column;
        align-items: center;
        display: none;
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section id="new-tweet">
          <h2>Compose Tweet</h2>
    
          <form id="tweet-form" method="POST" action="/tweets">
        
          <label for="tweet-text"></label>
          //text area id="tweet=text" has no relevant css classes applied to it (just background color)
          <textarea id="tweet-text" name="text" placeholder="What are you humming about?"></textarea>
          <div class="button-count">
            <button type="submit" class="submit-tweeet">Tweet</button>
            <output name="counter" id="tx-counter" class="counter" for="tweet-text"></output>
          </div>
    
          </form>
        </section>

任何帮助表示赞赏,谢谢。

标签: htmljquerycss

解决方案


I think you should use toggle would be more reasonable

 $('.call-to-action').on('click', function() {
         $('#new-tweet').stop().toggle('slow');
      });


推荐阅读