【问题标题】:How can I move the collapse button to the bottom upon clicking?单击时如何将折叠按钮移至底部?
【发布时间】:2020-01-24 11:38:25
【问题描述】:

我正在使用引导程序创建一张可以在点击时展开的卡片。为此,我正在使用崩溃。但是当我使用折叠按钮时,按钮保持不动,而我希望它移动到卡片的底部。底部的图片也应该很清楚地说明我正在尝试做什么。

点击折叠时如何向下移动按钮?我必须使用 Javascript 吗?

感谢阅读本文

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
  <div class="col-2">
      <!-- horizontal spacing -->
  </div>
  <div class="col-8 ">
    <div class="card text">
      <div class="card-header">
        <div class="row">
          <div class="col-3">
            <div class="text-primary"> Name Nameson </div>
          </div>
          <div class="col-6">
            <!-- horizontal spacing -->
          </div>
          <div class="col-3">
            <div class="float-right text-secondary"> Aug 21 2019 </div>
          </div>
        </div>
      </div>
      <div class="card-body">
        <h5 class="card-title">Average Rating (4.5) </h5>
        <p class="card-text">Contrary to popular belief, Lorem Ipsum is not </p>

      </div>
      <div class="card-footer text-muted text-center">
        <a href="#" class="btn" data-toggle="collapse" data-target="#review">
          <div class="row">
          <div> Click to see full review </div>
          </div>
          <span class="oi oi-caret-bottom"></span>
        </a>
        <div class="collapse" id="review">
          Content goes here
        </div>
      </div>
    </div>
  </div>
</div>

【问题讨论】:

  • 将可折叠的 div 放在锚点上方
  • 对于那些正在寻找做类似事情的人(最后的折叠按钮):您还应该知道您正在触发您的用户。当用户点击展开按钮时,大多数时候他会在显示 2-3 页的内容时立即后悔,因此他们想立即折叠并跳过内容。最后有折叠按钮会迫使用户痛苦地滚动。更何况有时候,点击后,页面不会再次向上跳转,所以你必须再次向上滚动才能恢复初始内容

标签: jquery html css twitter-bootstrap bootstrap-4


【解决方案1】:

将附加内容移动到卡片页脚上方的单个collapse div...

https://codeply.com/p/R3QbJnLQDE

         <div class="card text">
                <div class="card-header">
                    <div class="row">
                        <div class="col-3">
                            <div class="text-primary"> Name Nameson </div>
                        </div>
                        <div class="col-6">
                            <!-- horizontal spacing -->
                        </div>
                        <div class="col-3">
                            <div class="float-right text-secondary"> Aug 21 2019 </div>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <h5 class="card-title">Average Rating (4.5) </h5>
                    <p class="card-text">Contrary to popular belief, Lorem Ipsum is not </p>
                </div>
                <div class="collapse" id="review">
                    <div class="card-body">
                        <h5 class="card-title">More </h5>
                        <p class="card-text">Contrary to popular belief, Lorem Ipsum is not </p>
                    </div>
                    ... (additional content sections here)
                </div>
                <div class="card-footer text-muted text-center">
                    <a href="#" class="btn" data-toggle="collapse" data-target="#review">
                        <div class="row">
                            <div> Click to see full review </div>
                        </div>
                        <span class="oi oi-caret-bottom"></span>
                    </a>
                </div>
         </div>

【讨论】:

    【解决方案2】:

    所有你需要重组你的DIV,在哪里分开你需要展示主动性和onClick事件显示更多......

    HTML:

    <div class="container">
      <div class="row">
        <div class="col-2">
          <!-- horizontal spacing -->
        </div>
        <div class="col-8 ">
          <div class="card text">
            <div class="card-header">
              <div class="row">
                <div class="col-3">
                  <div class="text-primary"> Name Nameson </div>
                </div>
                <div class="col-6">
                  <!-- horizontal spacing -->
                </div>
                <div class="col-3">
                  <div class="float-right text-secondary"> Aug 21 2019 </div>
                </div>
              </div>
            </div>
            <div class="card-body">
              <div class="inital">
                <h5 class="card-title">Average Rating (4.5) </h5>
                <p class="card-text">Contrary to popular belief, Lorem Ipsum is not </p>
              </div>
              <div class="ondemand">
                <div class="section">
                  <h5 class="card-title">Average Rating (4.5) </h5>
                  <p>Be sure to have your pages set up with the latest design and development standards. That means using an HTML5 doctype and including a viewport meta tag for proper responsive behaviors. Put it all together and your pages should look like this</p>
                </div>
                <div class="section">
                  <h5 class="card-title">Average Rating (4.5) </h5>
                  <p>Be sure to have your pages set up with the latest design and development standards. That means using an HTML5 doctype and including a viewport meta tag for proper responsive behaviors. Put it all together and your pages should look like this</p>
                </div>
                <div class="section">
                  <h5 class="card-title">Average Rating (4.5) </h5>
                  <p>Be sure to have your pages set up with the latest design and development standards. That means using an HTML5 doctype and including a viewport meta tag for proper responsive behaviors. Put it all together and your pages should look like this</p>
                </div>
              </div>
            </div>
            <div class="card-footer text-muted text-center">
              <a href="#" class="btn" data-toggle="collapse" data-target="#review">
                <div class="row">
                  <div class="showmore">Load more</div>
                  <div class="showless">Show Less</div>
                </div>
                <span class="oi oi-caret-bottom"></span>
              </a>
              <div class="collapse" id="review">
                Content goes here
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    

    JS: Jquery -

    $(document).ready(function(){
    
      $('.ondemand').hide();
      $('.showmore').show();
      $('.showless').hide();
    
      $('.showmore').on('click', function(){
        $('.ondemand').slideDown("slow", "swing");
        $('.showmore').hide();
        $('.showless').show();
      });
    
      $('.showless').on('click', function(){
        $('.ondemand').slideUp("slow", "swing");
        $('.showmore').show();
        $('.showless').hide();
      });
    
    
    });
    

    这里是演示:link

    【讨论】:

      猜你喜欢
      • 2015-11-18
      • 2012-11-30
      • 2023-03-05
      • 2016-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      相关资源
      最近更新 更多