jQuery dotdotdot on accordion menu

Robby Huska

So I have a set of accordions that I use to show and hide extra content. I am using jQuery's .animate() to do so (well in this case it is using velocity, but essentially the exact same). The closed height shows a few lines of text (height: 95px), and the open height animates to height: auto, (kind of, there is a little trick to get the auto height). And the same in reverse, it animates to the closed height.

My issue is, I am trying to add jQuery dotdotdot http://dotdotdot.frebsite.nl/ to have the closed ones truncated. I can of course get this to work on load, that is the commented portion at the top.

I have created a codepen that has everything already loaded up. I was just hoping someone could help me get the dotdotdot portion working.

Here is the link to the codepen too: http://codepen.io/anon/pen/pvaroR

jQuery(function($){

  //$('.accordion-content').dotdotdot();

  $('.accordion-title').on('click', function(){
    var content = $(this).next();

    if ($(this).parent().hasClass('open')) {
      content.velocity({ 'height' : 95 });
      $(this).parent().removeClass('open').addClass('closed');
    } else {

      // Sets height to auto quickly
      content.css({ 'height' : 'auto' });

      // Store that value in a variable
      var contentHeight = content.height();

      // Sets height back to "closed" height
      content.css({ 'height' : 95 });

      $(this).parent().removeClass('closed').addClass('open');

      // animates to strored variable height
      content.velocity({ 'height' : contentHeight });

    }
  });
});
Tim Banks

The dotdotdot plugin doesn't make it very easy to get the original content back in to the original form. I used a combination of the originalContent event and then reinitializing the dotdotdot on the accordion content.

The pseudo-code looks like this:

when title is clicked {
    if content was open {
        call .dotdotdot on content
        animate height down to fit content
    } else content was closed {
        get original content and put it back
        get new height, set back to lower height, animate to regular height
    }
}

You can view the udpated CodePen here: http://codepen.io/anon/pen/XJZaYP

Updated CodePen with the .dotdotdot() being called in the velocity callback: http://codepen.io/anon/pen/myXzwW

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

adding menu to jquery accordion

From Dev

jquery accordion menu with nested

From Dev

Resize Accordion Menu jQuery

From Dev

JQuery accordion menu with nested accordion menus

From Dev

jquery - vertical accordion navigation menu

From Dev

Jquery accordion menu active open

From Dev

Jquery accordion menu active open

From Dev

jQuery sub-menu Accordion

From Dev

jQuery dotdotdot not working with calc

From Dev

Jquery accordion menu (3 level) How to?

From Dev

Keep Jquery accordion menu open on current page

From Dev

Some elements lag in jQuery accordion menu

From Dev

How to use jquery dynatree plugin as accordion menu?

From Dev

jquery accordion menu open middle on page load

From Dev

Accordion Jquery Multi-menu nav

From Dev

jquery accordion menu, make header hyperlink

From Dev

JQuery Expand Nested Accordion Menu by URL

From Dev

how make active jQuery Accordion Menu?

From Dev

Highlight parent menu when submenu is clicked in Jquery for accordion menu

From Dev

JQuery Accordion Menu in Conflict with mmenu - JQuery 1.4 vs 1.7

From Dev

How to create a simple three level jQuery Accordion menu?

From Dev

How to add arrow on the right side of jQuery accordion menu

From Dev

How to collapse jQuery accordion menu consisting of div's?

From Dev

Create an accordion dropdown menu for parent & child attributes using jquery or javascript

From Dev

Stop sliding up the current item on DC jQuery Vertical Accordion Menu

From Dev

Need a active submenu after refresh (jquery accordion menu)

From Dev

How to create a simple three level jQuery Accordion menu?

From Dev

jQuery.dotdotdot on grid layout -> empty spaces

From Dev

not open second menu of accordion menu

Related Related

HotTag

Archive