Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:26:17+00:00 2026-05-27T09:26:17+00:00

I have a div of which collapse and expands using slideToggle and easing. $(‘button’).click(function

  • 0

I have a div of which collapse and expands using slideToggle and easing.

$('button').click(function () {
    $('div').slideToggle('2000', "easeOutBounce");
});

I want it when it slide’s Up to have a minimum height so that there always a small visible content of it.

So when it’s slide down has height:(div height) and on slideUp, height:10px;

Note that the div could have any amount of height so that’s why I am not using animation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:26:17+00:00Added an answer on May 27, 2026 at 9:26 am

    The best I could come up with is the following:

    var toggleMinHeight = 30,
        duration = 2000,
        easing = 'swing';
    $('.toggles').each(
        function(){
            $(this).attr('data-height',$(this).height());
        }).click(
        function(){
            var curH = $(this).height();
            if ($(this).is(':animated')){
                return false;
            }
            else if (curH == $(this).attr('data-height')) {
                $(this).animate(
                    {
                        'height' : toggleMinHeight
                    }, duration, easing);
            }
            else if (curH == toggleMinHeight){
                $(this).animate(
                    {
                        'height' : $(this).attr('data-height')
                    }, duration, easing);
            }
        });
    

    JS Fiddle demo.

    This demo has some issues, however:

    • No easing functionality beyond that specified by the basic jQuery library (giving access to ‘swing’ and ‘linear’), this could be improved by including jQuery UI, however.
    • It could almost certainly be made into a plug-in, to be somewhat less icky to look at.
    • Requires a large, functional but not pretty, if/else if statement.
    • Requires at least one pass of the each() to assign the ‘default’/’natural’ height of the div elements.
    • If the divs aren’t position: absolute they shrink down to the baseline of the in-line elements (as they’re display: inline-block), this may not be a problem if they’re float: left (or float: right, obviously).

    Hopefully it’s of use, but it’s certainly not ideal in its current state.


    Edited to post the plugin-ised version of the above (it retains all the same issues as before):

    (function($) {
    
        $.fn.slideTo = function(slideToMin, duration, easing) {
    
            var slideToMin = slideToMin || 30,
                duration = duration || 500,
                easing = easing || 'linear';
            $(this)
                .attr('data-height', $(this).height())
                .click(
                    function() {
                        var curH = $(this).height();
                        if ($(this).is(':animated')) {
                            return false;
                        }
                        else if (curH == $(this).attr('data-height')) {
                            $(this).animate({
                                'height': slideToMin 
                            }, duration, easing);
                        }
                        else if (curH == slideToMin) {
                            $(this).animate({
                                'height': $(this).attr('data-height')
                            }, duration, easing);
                        }
                    });
    
            return $(this);
        };
    })(jQuery);
    
    $('.toggles').slideTo(50,1500,'swing');
    

    JS Fiddle demo.

    1. slideToMin: this can be either a quoted string, such as ‘3em’, ’20px’, or an unquoted number, such as 30, and represents the height to which you want the element to slide to. If there are no units supplied then the height is, by default, considered to be in pixels.
    2. duration: the number of milliseconds for which the animation lasts.
    3. easing: a quoted string defining the type of easing to be used in the animation; without jQuery UI this is either ‘linear’ or ‘swing’. With jQuery UI other options may be possible, but this is untested. If unspecified the animation defaults to ‘linear.’ Because using units in a quoted string causes the final else if to return false (obviously, I suppose…sigh), please use only an unquoted numerical argument for this variable (or edit the plug in to properly deal with quoted strings with units…).

    A larger issue that I hadn’t realised until I posted this, is that the plugin version only allows one iteration of the animation. Which I’m confused about, though perhaps it’s obvious to someone else?

    Okay, it appears to be the evaluation of the height in the if statement. Using 3em caused the final else if : curH == toggleMinHeight to return false. Presumably due to the presence of the unit (em) in that variable. The above guidance has been edited to reflect that the units should not be used.


    References:

    • animate().
    • :animated selector.
    • attr().
    • click().
    • each().
    • height().
    • is().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div which opens when I click a menu button, I am
I want to make the div's expand/collapse on the jquery click function I have
I have a div called address which as a textarea. When I click a
I have a collapsible div implemented in js, the function of which is show/hide
I have a div in default.aspx which has a masterpage. Masterpage has a expand/collapse
I have a div which I have attached an onclick event to. in this
I have a div which displays the current value of the slider and the
I have a div which needs to be positioned statically / relatively. When it
I have one aspx page with some controls. Also i have one DIV which
I have a div in which a page is loaded with the DojoX Layout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.