Explore button that gradually decreases max-height

I have a "Show More" button that expands a div by removing the css attribute max-height, but I want to add an animation similar to jQuery's slideToggle() function to smoothly reveal the rest of the content.

This is the code I am using:

<div id="Presentation" style="text-align:justify;"><?php echo $data['texte_presentation'];?></div>
            <div id="fadeout" class="fadeout" style="display:none;"></div>
                <div id="DivReadMore" style="text-align:right;margin-top:-4em;display:none;">
                <hr style="margin:5px;"><button id="BoutonReadMore" class="btn btn-warning btn-block"><i class="fa fa-plus"></i> Show More</button>
                </div>
            <script>
            $(document).ready(function () {
                ReadMore();
                $(window).on('resize', function(){
                    if($('#Presentation').hasClass("read-more"))
                    {}else{
                      ReadMore();
                    }
                });
                $("#BoutonReadMore").click(function(){
                  $("#Presentation").css({'max-height':'', 'overflow':''});
                  $("#DivReadMore").hide();
                  $("#fadeout").hide();
                  $("#Presentation").addClass("read-more");
                });
            });
            function ReadMore() {
                var height = $('#Presentation').height();
                if(height > 200)
                {
                    $("#Presentation").css({'max-height':'250px', 'overflow':'hidden'});
                    $("#fadeout").show();
                    $("#DivReadMore").show();

                }else{
                $("#Presentation").css({'max-height':'', 'overflow':''});
                    $("#fadeout").hide();
                    $("#DivReadMore").hide();
                }
            }
            </script>

Any suggestions on how to implement this animation?

Answer №1

To add a smooth transition effect to the block, include this CSS code: transition: ease 0.5s all;. If it doesn't work, it might be because there is no max-height set for the block.

A cool trick I often use is to significantly increase the max-height using jQuery.animate. This will result in a nice animation :)

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

Implement a personalized click function for the delete icon in the mini cart

Is there a way to customize the click event for the remove button in the mini cart? function ajax_call(){ $.ajax({ url: ajax_url, type: 'post', data: {action : 'remove_from_cart','cart_item_key' : 10}, ...

I'm trying to understand why the combination of boostrap 5 mx-auto d-block is not effectively centering a fluid image. Can anyone

My code seems to be very simple, yet I am puzzled as to why it is not working. I have removed any external CSS from the page that could potentially cause interference, but the image still refuses to center inside my column. I have searched extensively and ...

Error: mangosse is not recognized

Node keeps throwing the error 'ReferenceError: mangoose is not defined' in my face. The culprit seems to be this line: const dogSchema = new mangoose.Schema({ I made sure to install mongoose using npm $ npm i mongoose Check out the code belo ...

Ways to distribute varied Responsive Images

Welcome to our website: .php .jquery .yii based Depending on the width of the viewport, we require at least two different infographic images. The client is very particular about w3c validation The picturefill solution does not pass validat ...

Exploring the World of Dynamic Table ID Access in Rails 5 with Coffeescript

Within my Index view, I have a table that I want to dynamically populate with an ID. This is what I've attempted so far: id="table_<%= @controller_name %>" The method in my controller looks like this: def get_controller_name @controller_nam ...

Having difficulty assigning a value to the RadNumeric Text box during the OnBlur event

One of the requirements I have is that, when a user enters any number in a text box and tabs out, leading zeros should be added to the value in the text box. function AddPaddingToInvestmentNumber(sender, args) { var textBoxVar = "<%=txt1.ClientID ...

Disable a href link using Jquery after it has been clicked, then re-enable it after a

There are several <a target="_blank"> links on my website that trigger API calls. I want to prevent users from double clicking on these buttons. This is what I have tried: .disable { pointer-events: none; } $(document).ready(function(e) { ...

Why does parsing the GET response fail intermittently with Jquery, ajax, and JSON?

Currently, I am encountering an issue with ajax calls using jQuery where the response being returned is a JSON array. In certain scenarios, everything works perfectly fine. However, in other cases specifically in browsers like Firefox and IE11, there seems ...

Nested navigation in Bootstrap

I am currently working on creating a multilevel menu using Twitter Bootstrap. Check out the code here Below is the snippet of HTML code: <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> ...

Having trouble with the fancybox form

Take a look at this link for information on how to display a login form. Once you click on "Try now", follow these steps: A fancy box should open with fields for name and password. If both fields are left blank and the login button is clicked, an error ...

Ways to employ data binding for extracting a user-input value and performing multiplication operations with the enclosed {{ ...}} tags

My API response includes the price of a product, which is represented as {{price}} I have a system where I can add or reduce the number of products: <div class="number-input"> <h2>Price: {{price }}</h2> <button oncli ...

Navigating through a dropdown menu using Selenium in Javascript for Excel VBA - Tips and tricks

I need to access a web page using Excel VBA that is only compatible with Chrome or Firefox, not Internet Explorer. I have successfully accessed the website using Selenium, but I am having trouble navigating through the drop-down menu to reach the section w ...

Adding a detached element under certain conditions

When attempting to add a detached span based on a specific condition, I encountered the following situation. const arrow = d3 .create('span') .classed('arrow', true) .text('\u2192'); //d3.select('bod ...

Retrieve the array from the object only if it includes a specific string using jQuery

Using regex, I am able to query all square brackets in a string with the following command: var sizecolor = textvalue.match(/[^[\]]+(?=])/g); If the object above contains "SPrice", I want to retrieve the square bracket. For example: If my string lo ...

How can you incorporate a click function into a toggle function?

Currently, I have an accordion-style navigation set up with collapsible tabs and toggle buttons. I am attempting to make my 'tab' DIVs clickable. I implemented the following function into my code to reduce repetitive toggle() functions, but unfo ...

Is there a way to exclusively use ES6 to import jQuery from an npm package?

After installing jQuery using npm -install jquery, a node_modules folder was created in my project with the jQuery library inside. However, I encountered an error when trying to import it using ES6 import. I am looking for a solution that does not involve ...

Easy ways to manipulate the style of array components in Vue.js

Hey there all you programmers, I'm reaching out to see if any of you have insight on how I can modify the style of a specific component within an Object array. This is the code snippet: <template> <div> <ul> <li v-fo ...

What's the deal with inline blocks and text in the middle?

Check out this code I created for a navigation bar. HTML : <div class="header-nav"> <div class="header"> <img src="../Pictures/LifeFrame/2.jpg" width="100%" height="100px" /> </div> <div class="nav" align="c ...

Revolutionizing Interaction: Unveiling the Power of Bootstrap 3

Would you be able to assist me in customizing buttons to resemble a typical dropdown link? <div class="dropdown"> <button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">Dropdown <span class="caret"&g ...

Retrieve an array of 16 elements using React in a TypeScript environment

Exploring the new React 16 feature to return array elements within the render method is throwing a TypeScript error stating "Property 'type' is missing in type 'Element[]'" const Elements: StatelessComponent<{}> = () => ([ & ...