Steps to activate Slick slider by clicking (expand and collapse smoothly)

Looking to add a smooth slide down animation to some Slick sliders in my project.

Want the slider and "projects" button to smoothly slide down when the title above is clicked.

Currently, the slider/button container does slide down on click by toggling a class that changes the max-height of the container, but the slider and button just pop into view without any animation.

If you have any suggestions or code snippets for achieving a smooth slide down transition, please share them! View the codepen here

.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');
});

Answer №1

If you wish to animate the height using CSS without utilizing @keyframes, consider making a few modifications. To see if the desired effect is achieved and to view the slides in full screen mode, follow the instructions below.

$('.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 -->

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unraveling the intricacies of extracting data from nested object properties

Why do my variables stop being reactive after unwrapping from props? I have three components - a parent component, a second component for display, and a third component for updating data based on input (simplified code here). The third component updates ...

Creating a new deferred object by cascading the inner jqXHR in jQuery.ajax for wrapping and returning

I am currently working on developing a jQuery plugin and I need to perform some pre-process operations before $.ajax is triggered: // The signature is the same with $.ajax $.myAjax = function(url, options) { var data = options.data; var promises ...

Using a double for loop in VUE3 without altering the property

I am working with a 'data' props object that looks like this: data = [ { "label":"gender", "options":[ {"text":"m","value":0}, {"text":"f&q ...

What is the proper way to change this JavaScript variable into JSON format?

I have a JavaScript variable containing data that I need to convert into valid JSON format for easier parsing. The current variable structure is as follows: { "machines": [{ "category": "Category 1", "items": [{ "name": "Te ...

I'm currently attempting to determine the total cost of a series of operations, however, I am not receiving any results

Here is the code snippet from my HTML file: <tr> <td><input id="z1" type="number" oninput="calculateSubTotal()"> </td> <td>Shirts - WASH - Qty 1 to 4</td> <td>2.50 ea</td> ...

Issue: [unresolved] Provider not recognized: $resourseProvider <- $resourse <- Phone Angular factory

I'm encountering an issue with injecting a resource. Error: [$injector:unpr] Unknown provider: $resourseProvider <- $resourse <- Phone Here is my code: index.html <script src="bower_components/angular/angular.js"></script> < ...

Total of values that are continuously updated

I am working on a code snippet that dynamically updates the total cost of food items and clothing items separately as the user enters the value of each item. I am looking to display the combined Total Cost (sum of clothing + food inputs) which should be up ...

Sending documents via ExpressJS

I'm currently developing a small application using the latest NodeJS and ExpressJS, but I've encountered an issue with uploading files. My routes are set up like this: app.get('/Share', share.index); app.post('/Share/Process&apos ...

Is there a way to encode a clear image stream into base64 without saving it to the local storage

I'm looking for a way to change an image into base64 format using the azure-storage package. How can I accomplish this? this.blobService.getBlobProperties( 'container', path, (err, properties, ...

I am interested in running JavaScript code on a page that has been loaded through AJAX

I am struggling to execute the Javascript loaded within an ajax page. Here is the link to my loaded ajax page: https://jsfiddle.net/4dsbry7j/ JS : var xmlhttp = new XMLHttpRequest(); var url = "http://localhost/ajax/find2.php"; xmlhttp.onreadystatechang ...

Is it advisable to use mongoose for validating get parameters?

When it comes to my routing setup, I have a GET request: router.get('/getOne', auth(), mapController.getOne); Within the mapController file, I am passing an id parameter through the URL and executing a MongoDB query using Mongoose in the follow ...

Unable to integrate any modules or components from bit.dev into my React application

I am currently working on a React project and encountering an issue with importing a component from bit.dev. After installing the package via my terminal with the command: bit import nexxtway.react-rainbow/button You can find more information about it t ...

Strategies for embedding hyperlinks within paragraphs

I'm looking to create a main menu with two links that will direct users to specific paragraphs on a single page based on the link they click. For example, clicking on the first link should take them directly to the paragraph titled "My Title 1," and c ...

Troubleshooting: JavaScript code not functioning properly with variable input instead of fixed value

I have encountered an issue with a JS function that I'm using. The function is shown below: // A simple array where we keep track of things that are filed. filed = []; function fileIt(thing) { // Dynamically call the file method of whatever ' ...

I am facing an issue where the inline CSS is not being applied in my

I recently integrated tcpdf in my CodeIgniter project and encountered an issue with applying inline CSS to td. This is a snippet of my code: <table style="float:left;width:100%; border:1px solid #c2c2c2; margin-top:10px;"> <tr style="float:l ...

What is the best way to transfer information from a directive to a sibling element within the DOM?

Due to animation requirements, I decided to separate the directive and its value into different HTML elements. Once the directive is loaded, the separated element must be updated from the directive. How can I transmit the information from directive to ano ...

Searching for specific values within data attributes using jQuery wildcards

I am currently utilizing the data_attribute on this page and have the following elements with data attributes. No. 1.<div class="row hidden" data-party-registration-source-type-id="1"> 2.<div class="row hidden" data-party-registration-source- ...

Rearranging information within a JSON structure

Here is a sample of Javascript object and code to consider: Javascript Object { "thing":{ "data":"some data", "thumb":"some data", "data1":"some data", "data2":"some data", "data3":"some data", }, "extra1":[ ...

What is the best way to swap out an HTML file with another without altering the link?

I'm working on an HTML file, which is basically a webpage. My goal is to create a functionality where clicking a button will dynamically replace the content of the page with another HTML file, complete with its own CSS, JavaScript functions, and other ...

What is the best method to close a polygon infowindow when hovering over a map marker?

I am currently working on integrating Google Maps which includes a set of polygons representing state boundaries and markers representing cities within each polygon. I want to display information when hovering over a polygon/state. My question is: how can ...