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

  • Home
  • SEARCH
  • 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 9317851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:58:46+00:00 2026-06-19T02:58:46+00:00

I’m building a small app and I’m using AngularJS. Inside the app I need

  • 0

I’m building a small app and I’m using AngularJS. Inside the app I need a collapsible element and using Twitter Bootstrap would be as easy as adding the library and some tags on my target element and the trigger.

But I’m trying not to load other external libraries like bootstrap or any other, so I was trying to achieve the same behavior with Angular :

$scope.collapse = function(target) {

        var that = angular.element(document).find(target),

            transitioned = {
                'WebkitTransition' : 'webkitTransitionEnd',
                'MozTransition'    : 'transitionend',
                'OTransition'      : 'oTransitionEnd otransitionend',
                'msTransition'     : 'MSTransitionEnd',
                'transition'       : 'transitionend'
            },

            _transitioned = transitioned[ Modernizr.prefixed('transition') ],

            height = that.outerHeight(true);

        if (angular.element(that).hasClass("in")) {
            that.height(0);
        } else {
            that.height(height);
        };

        that.on(_transitioned, function() {
            that.toggleClass("in");
        });
    };

As you can see I’m trying to transition the height ( as the element has a transition on the height ) and in the end just add the class in. But that isn’t working very well because if I’m listening on the transition end it will trigger on any transition end inside that element.

I would need some help with this, how can I rewrite the bootstrap collapsible just with angular ? I don’t need the events that bootstrap has like on shown, hidden or show, hide, I just need to trigger a simple collapse of the element with transition and keep my elements height dynamic ( I don’t want a fixed height, otherwise I would just use CSS to achieve the collapse ). I just need to be pinpointed in the right direction 🙂

  • 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-06-19T02:58:47+00:00Added an answer on June 19, 2026 at 2:58 am

    Seems like you want to just collapse something with CSS3 transitions?

    Well, you can do that, but the controller is the wrong place to be doing that. You should do that with directives or in a custom directive. Fortunately, you can do it with the Angular native directives, such as ng-class.

    HTML:

    <button ng-click="open = !open">Toggle</button>    
    <div ng-class="{ showMe: open }" class="collapsable">
      <h3>This should collapse</h3>
    </div>
    

    And most importantly, your CSS:

      .collapsable {
        display: inline-block;
        overflow: hidden;
        height: 0;
        transition: height 1s;
        -webkit-transition: height 1s;        
        -moz-transition: height 1s;        
        -o-transition: height 1s;         
      }
      .collapsable.showMe {
        height: 100px;
      }
    

    And here is a plunker of it working.

    Important to note, CSS3 transitions will not work in all browsers. Particularly in IE. In the end, I think you’d probably be better off using a plugin that someone else already made, and then leveraging it in a custom directive that watched some boolean value.

    I hope that helps.


    EDIT

    height: auto does not work with CSS Transitions (at least as of the time of this post). So, this is why you’ll really want to use someone else’s plugin, rather than reinvent the wheel. Even if it’s just JQuery’s animate() method. The psuedo-code for rolling your own directive would be something like so: (presuming you’re using JQuery)

    app.directive('collapseWhen', function () {
       return function(scope, elem, attr) {
         scope.$watch(attr.collapseWhen, function(val) {
            var clone = elem.clone().appendTo('body');
            var h = clone.height();
            clone.remove();
            scope.animate({ height: (val ? h : 0) + 'px' }, 1000);
         }
       }
    });
    

    and then you’d use it like:

    <button ng-click="foo = !foo">Toggle</button>
    <div collapse-when="foo">
    

    Again, the above is psuedo-code, I have no idea if it will work or not, it’s just to give you an idea to follow if you really want to roll your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.