Ways to make text within a container smoothly slide down

Hello, I have a question about jQuery as I am relatively new to it.

I am currently working on creating a team members section where clicking on a team member will slide down information about that person underneath.

I have managed to set up the parent container to detect the height of the team member's information and animate in height dynamically for each person. This ensures that other team members are not covered up as they are pushed down accordingly.

However, my problem lies in the fact that the information about the person simply appears without any smooth animation like the rest of the elements do. I attempted to animate the ".team-content-container" with an initial height of zero, but faced some issues.

Is there a way for me to make the entire section smoothly animate into view?

Any assistance would be greatly appreciated!

Link to codepen: https://codepen.io/Finches/pen/jYKmEd

// Show/hide content from clicking box title
$('.open-team-box').click(function() {

  //Get height of content
  var height = $(this).siblings('.team-content-container').height() + 350;

  //Convert height to string
  var heightStr = height.toString();

  //Toggle height and content box display
  if ($(this).parent('.team-container').height() == 350) {
      $(this).parent('.team-container').animate({height: heightStr});
      $(this).siblings('.team-content-container').show();
    console.log(height);
    }
  else if ($(this).parent('.team-container').height() == height) {
      console.log('test');
      $(this).siblings('.team-content-container').hide();
      $(this).parent('.team-container').animate({height: "350px"});
    }
});

Answer №1

If you want to implement a toggle functionality, you could consider using the initToggle() method:

function initToggle(){
  $('.team-content-container').hide();
  $('.team-container').animate({height: "350px"});
}

$('.open-team-box').click(function() {
    initToggle();
      
      var height = $(this).siblings('.team-content-container').height() + 350;

      var heightStr = height.toString();

      if ($(this).parent('.team-container').height() == 350) {
          $(this).parent('.team-container').animate({height: heightStr});
          $(this).siblings('.team-content-container').show();
          console.log(height);
        }
    })

;

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

Tips on how to select the clicked class within a div using AJAX

Can you please explain how the browser stores content from a div called in ajax? I'm confused about why I can't directly target the content called in ajax and displayed in the browser inspector with jQuery. Also, how can I easily target a class ...

Fullcalendar JSON data sources

Currently, I am working on creating dynamic calendar events that trigger a controller function whenever the date or month changes. The controller then filters values received from an Ajax call with start and end parameters. Below are the functions involved ...

Confirm that a certain input is correct using jQuery validation

Is there a way to use jQuery validation to check if a user inputs a value greater than or equal to 5 in a form field? If the value is indeed greater than or equal to 5, an error message should be displayed. How can this be implemented? <input type=&apo ...

Verify whether an image is present without actually displaying it

I am currently integrating a script for hover-functionality: function VerifyImage(url) { var httpRequest = new XMLHttpRequest(); httpRequest.open('HEAD', url, false); httpRequest.send(); return httpRequest.status != 404; } The c ...

Struggling with passing custom headers in Rails, jQuery, and Ajax interactions

I'm having trouble sending custom headers to a Rails API, and I keep encountering this frustrating issue! ActionController::RoutingError (No route matches [OPTIONS] "/api/v1/surveys") In my application_controller.rb, I've added the code below ...

JSPM fails to load dependencies correctly

I have made a fork of the official Bootstrap repository (4.0.0-alpha.6) in order to switch from Grunt to Gulp, and to customize Bootstrap for our specific requirements. The project we are working on utilizes JSPM for package management. However, when atte ...

Tips for showing JSON data within multiple <div> elements on an HTML page with AngularJS and ng-repeat

I am looking to display JSON values on my HTML page, each in a separate div based on the image URL value from the .json file. However, I am encountering difficulties in displaying these values in the divs. Can someone please guide me on how to iterate and ...

Storing multiple text box values into a single application variable in C# - A Comprehensive Guide

[code page="c#"] Hdnano.Value = Application["AccountNum"].ToString(); $(document).ready(function() { $("#ano").on("blur", function() { var accountNum = $('textarea#ano').val(); $("#Hdnano").val(folioNum); }); &l ...

Adjust the height of the parent element containing the divs nested within the span

I recently created a unique square grid of SVG icons and positioned them directly to the right of some text within a header. The code for creating this grid looks like this: <div>HEADER TEXT <span> <div> <svg></ ...

Display an aspx page within a div container

I am using the following code to load an aspx page in a div tag. Unfortunately, it's not working as expected. Can someone please assist me in resolving this issue? <script type="text/javascript"> $(document).ready(function () { $(&a ...

Can you explain the purpose of using "link href="#""?

While browsing through the source code of a website, I came across this interesting snippet. <link href="#" id="colour-scheme" rel="stylesheet"> I'm curious, what exactly does this code snippet do? ...

Guidelines for sending JSON Data via Request Body using jQuery

I'm not well-versed in jQuery, so consider me a beginner. Here's my code that is not correctly handling JSON data submission via Request Body. <!doctype html> <html lang="en> <head> <title>jQuery JSON Data Submission ...

Modifying CSS styles in real-time according to the present data

Is there a way to dynamically change CSS values based on current CSS values? For example, instead of explicitly setting different values like this: .test{ margin-top:100px; } .test:hover{ margin-top:90px; } Is it possible to achieve the same eff ...

Custom Jquery function is failing to position divs correctly within ajax-loaded content

I recently coded a custom function that efficiently positions absolute divs within a container by calculating top positions and heights: $.fn.gridB = function() { var o = $(this); //UPDATED from var o = $(this[0]); o.each(function() { var ...

How can I resize my image to match the dimensions of the navigation bar?

Is there a way for me to match the width of my navigation bar with that of an image? The issue I'm facing is that the original size of the image is 497 x 298px, and in order to stretch it across the full width of the page while maintaining margins of ...

loop through the links using their unique identifiers

Here is my current code in Jade/Pug: #pm_language.dropdown(aria-haspopup='true', aria-expanded='false') button#langbutton.btn.btn-primary.dropdown-toggle(type='button', data-toggle='dropdown') Lang [RU] ...

Change the body selector in CssResource to apply custom styles

I have implemented a CssResource within a ClientBundle following the guidelines provided in the documentation at this link. To access the styles from my UiBinder xml, I have used ui:with as explained in the documentation available at this guide. While th ...

Need help positioning this HTML iframe on my webpage?

Can anyone help me figure out how to position this HTML i-frame in a specific place on my webpage? <div style="overflow: hidden; width: 333px; height: 156px; position src="h: relative;" id="i_div"><iframe name="i_frame"http://url.com/click.php?a ...

Error message: validator is not defined when integrating jquery.validate with jquery.uploadfile package

Currently, I am facing an issue while attempting to incorporate both jquery.validate and jquery.uploadfile on the same page. The error message I'm receiving is: TypeError: validator is undefined if ( validator.settings.rules ) { Interestingly, if ...

The selenium element for the submit button is currently not responsive to interactions

Recently, I encountered some challenges with selenium, specifically the anticaptcha API. Although I managed to resolve that issue, I am currently facing a different problem. Below is my existing code: from time import sleep from selenium import webdriver f ...