javascript - 如何在单击时切换 Slick slider (向下滑动并向上滑动)

标签 javascript jquery css slick.js

我正在尝试在某些 Slick slider 上获得平滑的向下滑动动画。

我需要 slider 和“元素”按钮在单击上述标题时以向下滑动的方式进行动画处理。

我有它, slider /按钮容器确实在单击时向下滑动(切换一个改变容器最大高度的类),但是 slider 和按钮只是弹出到 View 中并且不会向下动画容器。

Codepen 链接:https://codepen.io/Finches/pen/jYrzWv

在此处实现平滑的向下滑动过渡有什么帮助吗?代码片段...

.service-content-wrapper {
  margin: 0 auto;
  width: 100%;
  visibility: hidden;
  margin-bottom: 25px;
  max-height: 0;
  transition: max-height 2s;
}

.accordion-content-wrapper {
  background: blue;
}

.active {
  max-height: 1000px;
  visibility: visible;
}

-

$('.title-box').click(function() {
  $(this).siblings('.service-content-wrapper').toggleClass('active');
});

最佳答案

如果您想在不使用 @keyframes 的情况下通过 css 设置高度动画,您可能需要更改一些内容,看看下面是否是您想要的幻灯片显示方式,请尝试全屏查看。

$('.accordion-content-wrapper').slick({
  prevArrow: false
});

$('.title-box').click(function() {
  $(this).siblings('.service-content-wrapper').toggleClass('active');
});
body {
  font-family: 'Open Sans', sans-serif;
}

.title-box h1 {
  margin: 0 auto;
  text-align: center;
  padding: 25px;
}

.service-content-wrapper {
  margin: 0 auto;
  width: 100%;
  /*   margin-bottom: 25px; */
  height: 0px;
  position: relative;
  transition: 1s;
}

.accordion-content-wrapper {
  background: blue;
}

.active {
  transition: 1s;
  height: 350px;
}

.slide-1,
.slide-2 {
  width: 100%;
}

.slick-next {
  position: absolute;
  bottom: 10px;
  right: 10px;
}

.title-box {
  background: gray;
  width: 100%;
  z-index: 9999 !important;
  position: relative;
}

.service-container {
  /*   background: pink; */
  margin: 10px;
  overflow: hidden;
  position: relative;
}

.page-container {
  padding: 25px;
}

.btn {
  padding: 15px;
  background: salmon;
  text-align: center;
  text-transform: uppercase;
  font-weight: 900;
  margin-top: 15px;
  margin-bottom: 15px;
}

.btn:hover {
  background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<div class="row page-container">

  <div class="col-md-4 col-xs-12 services-column">

    <div class="service-container">

      <div class="title-box col-md-12">
        <h1>HEAVY CIVIL</h1>
      </div>

      <div class="service-content-wrapper">

        <div class="accordion-content-wrapper col-md-12">

          <div class="slide-1 col-md-12">
            This is test content.
          </div>
          <!-- slide-1 -->

          <div class="slide-2 col-md-12">
            <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
              here, content here', making it look like readable English.</p>
            <p> Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes
              by accident, sometimes on purpose (injected humour and the like).</p>
          </div>
          <!-- slide-2 -->

        </div>
        <!-- accordion-content-wrapper -->

        <div class="btn col-md-12">PROJECTS</div>

      </div>
      <!-- service-content-wrapper -->

    </div>
    <!-- service-container -->

    <div class="service-container">

      <div class="title-box col-md-12">
        <h1>HEAVY CIVIL</h1>
      </div>

      <div class="service-content-wrapper">

        <div class="accordion-content-wrapper col-md-12">

          <div class="slide-1 col-md-12">
            This is test content.
          </div>
          <!-- slide-1 -->

          <div class="slide-2 col-md-12">
            <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
              here, content here', making it look like readable English.</p>
            <p> Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes
              by accident, sometimes on purpose (injected humour and the like).</p>
          </div>
          <!-- slide-2 -->

        </div>
        <!-- accordion-content-wrapper -->

        <div class="btn col-md-12">PROJECTS</div>

      </div>
      <!-- service-content-wrapper -->

    </div>
    <!-- service-container -->

  </div>
  <!-- col-md-4 -->

  <div class="col-md-4 col-xs-12 services-column">

    <div class="service-container">

      <div class="title-box col-md-12">
        <h1>HEAVY CIVIL</h1>
      </div>

      <div class="service-content-wrapper">

        <div class="accordion-content-wrapper col-md-12">

          <div class="slide-1 col-md-12">
            This is test content.
          </div>
          <!-- slide-1 -->

          <div class="slide-2 col-md-12">
            <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
              here, content here', making it look like readable English.</p>
            <p> Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes
              by accident, sometimes on purpose (injected humour and the like).</p>
          </div>
          <!-- slide-2 -->

        </div>
        <!-- accordion-content-wrapper -->

        <div class="btn col-md-12">PROJECTS</div>

      </div>
      <!-- service-content-wrapper -->

    </div>
    <!-- service-container -->

    <div class="service-container">

      <div class="title-box col-md-12">
        <h1>HEAVY CIVIL</h1>
      </div>

      <div class="service-content-wrapper">

        <div class="accordion-content-wrapper col-md-12">

          <div class="slide-1 col-md-12">
            This is test content.
          </div>
          <!-- slide-1 -->

          <div class="slide-2 col-md-12">
            <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
              here, content here', making it look like readable English.</p>
            <p> Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes
              by accident, sometimes on purpose (injected humour and the like).</p>
          </div>
          <!-- slide-2 -->

        </div>
        <!-- accordion-content-wrapper -->

        <div class="btn col-md-12">PROJECTS</div>

      </div>
      <!-- service-content-wrapper -->

    </div>
    <!-- service-container -->

  </div>
  <!-- col-md-4 -->

  <div class="col-md-4 col-xs-12 services-column">

    <div class="service-container">

      <div class="title-box col-md-12">
        <h1>HEAVY CIVIL</h1>
      </div>

      <div class="service-content-wrapper">

        <div class="accordion-content-wrapper col-md-12">

          <div class="slide-1 col-md-12">
            This is test content.
          </div>
          <!-- slide-1 -->

          <div class="slide-2 col-md-12">
            <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
              here, content here', making it look like readable English.</p>
            <p> Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes
              by accident, sometimes on purpose (injected humour and the like).</p>
          </div>
          <!-- slide-2 -->

        </div>
        <!-- accordion-content-wrapper -->

        <div class="btn col-md-12">PROJECTS</div>

      </div>
      <!-- service-content-wrapper -->

    </div>
    <!-- service-container -->

    <div class="service-container">

      <div class="title-box col-md-12">
        <h1>HEAVY CIVIL</h1>
      </div>

      <div class="service-content-wrapper">

        <div class="accordion-content-wrapper col-md-12">

          <div class="slide-1 col-md-12">
            This is test content.
          </div>
          <!-- slide-1 -->

          <div class="slide-2 col-md-12">
            <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
              here, content here', making it look like readable English.</p>
            <p> Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes
              by accident, sometimes on purpose (injected humour and the like).</p>
          </div>
          <!-- slide-2 -->

        </div>
        <!-- accordion-content-wrapper -->

        <div class="btn col-md-12">PROJECTS</div>

      </div>
      <!-- service-content-wrapper -->

    </div>
    <!-- service-container -->

  </div>
  <!-- col-md-4 -->

</div>
<!-- row -->

关于javascript - 如何在单击时切换 Slick slider (向下滑动并向上滑动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47916089/

相关文章:

javascript - 使用 javascript 内联样式 div

javascript - 如何将 AJAX 请求从 vanilla JS 重写为 JQuery?

jquery - 查询 Javascript 库

css 背景图像被截断

css - 数字键盘android stretch网站模板

javascript - 将 div 扩展到完整页面大小,内容已经到位

javascript - 如何使用HTML5和JS选择具有唯一ID的音频文件URL?

python - flask css没有更新

javascript - 循环遍历对象数组并在 JSON 中添加对象 - Javascript

javascript - 附加子按钮的功能