javascript - collapse article when next article is expanded (Readmore.js - Extension) -



javascript - collapse article when next article is expanded (Readmore.js - Extension) -

i'm using readmore.js plugin. looked various solutions next issue none of them seemed perfect.

i want add together function collapses expanded article - if any, when readmore pressed.

thank's josh, manage flag variable isopen true or false when article expanded/collapsed. i'm trying figure out how collapse article when new 1 expanded.

<script> $('#info').readmore({ morelink: '<a href="#">more examples , options</a>', maxheight: 390, aftertoggle: function(trigger, element, expanded) { if(! expanded) { // "close" link clicked $('html, body').animate( { scrolltop: element.offset().top }, {duration: 100 } ); } } }); $('article').readmore({maxheight: 240}); var isopen = true; $('article').readmore({ aftertoggle: function(trigger, element, expanded) { if (expanded) { isopen = true; } if(! expanded) { isopen = false; } } }); $('article').readmore({ beforetoggle: function(trigger, element, expanded) { if (isopen) { } } }); </script>

thanks already...

as readmore.js adds class expanded blocks can identify , close them this:

$('article').readmore({ beforetoggle: function(trigger, element, expanded) { $( '.readmore-js-expanded' ).readmore( 'close' ); } } );

edit: seeing readmore.js not seem provide 'close' method may need false triggering close event on anchor:

$('article').readmore({ lesslink: '<a class="readmore-lesslink">show less</a>', beforetoggle: function(trigger, element, expanded) { $( '.readmore-js-expanded' ) .find( 'a.readmore-lesslink' ) .trigger( 'click' ); } } );

i did not test @ should started guess.

javascript jquery

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -