If you have make JS hide most of the content onload, the user will see the full content while the page is loading and when the last image has been downloaded (usually the slowest things on a page), then the onload event fires and all the JS magic is done.
YouTube do it like this:
HTML Code:
<div id="vidDescDiv">
<span id="vidDescBegin">Dan tries to run up the longest escal...</span>
<span id="vidDescRemain">Dan tries to run up the longest escalator in Western Europe the wrong way twice.</span>
<span id="vidDescMore" class="smallText"> (<a href="#" class="eLink" onclick="showInline('vidDescRemain'); hideInline('vidDescMore'); hideInline('vidDescBegin'); showInline('vidDescLess'); return false;" rel="nofollow">more</a>)</span>
<span id="vidDescLess" class="smallText">(<a href="#" class="eLink" onclick="hideInline('vidDescRemain'); hideInline('vidDescLess'); showInline('vidDescBegin'); showInline('vidDescMore'); return false;" rel="nofollow">less</a>)</span>
</div>
All they're doing is swapping display:none between two spans and two other spans (the content and the less/more links). It's probably the simplest way. You would have to truncate the text on the server side and add the ellipsis at the end of it.
You could reduce the extra markup by making the content have overflow:hidden and a short height and then set the height to auto when the link is clicked (and change the link text to 'less'). You would have to work with ems there to make sure the height is always, say, three lines high when minimised:
HTML Code:
<div class="interview">
<p>This is a long interview. This is a long interview. This is a long interview.</p>
<p>This is a long interview. This is a long interview. This is a long interview.</p>
<p>This is a long interview. This is a long interview. This is a long interview.</p>
<p>This is a long interview. This is a long interview. This is a long interview.</p>
<p>This is a long interview. This is a long interview. This is a long interview.</p>
<span class="moreorless">... <a href="#">(more)</a></span>
</div>
Code:
.interview {
line-height:1.5em;
height:4.5em;
overflow:hidden;
position:relative;
}
.interview .moreorless {
position:absolute;
right:0;
bottom:0;
background:#FFF;
}
If the third line happens to be where a paragraph finishes, that's OK, but if it's in the middle of a paragraph, then the span will cover some of it with the ellipsis and the (more) link. You have to decide if that looks OK.
Then with javascript you have to find all the spans with the "moreorless" class and put them in an array. Then loop through them and attach an onclick event to the anchor inside each one that sets the parent div's (the .interview) height to auto and the link itself's text to less. Best way to do this would be by attaching another class to it and then removing it when it's clicked again.
Bookmarks