Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery slideToggle: jumpy at the end

Just wrote something up for a .slideToggle for a "Read more.../Read less...", the issue is that at the end of the slide, the animation "jumps", for a lack of a better description. Likewise when the slide is started again. Any suggestions?

I have it in jsFiddle

EDIT: I'm using Chrome

<div class="details">
<p>I am an excerpt.</p>
    <span class="show">Read More...</span>

        <div class="info">
        <p>the info to show in here......</p>
        </div>
        </div> <!-- details -->

<div class="details">
<p>I am an excerpt.</p>
    <span class="show">Read More...</span>

        <div class="info">
        <p>Some different info to show in here......</p>
        </div>
        </div> <!-- details -->

$(document).ready(function (){

    $(".info").hide();
        $(".show").click(function(event) {
        $(this).parent(".details").children("div.info").slideToggle(300);
        $(this).text($(this).text() == 'Read More...' ? 'Read Less...' : 'Read More...');
    });

});

Thanks!

like image 637
alexwc_ Avatar asked Sep 23 '13 22:09

alexwc_


1 Answers

You can eliminate the jumpiness by removing the margin on the last child element the sliding container. I believe it has something to do with jquery calculating the height including the margin, then when display block is applied the margins collapse on the others.

.info p{
    margin-bottom:0;
}

http://jsfiddle.net/QzStg/4/

like image 164
mikes000 Avatar answered Oct 13 '22 09:10

mikes000