i having trouble jquery function have created news page. able find number of rows/lines/sentences in amount of text ( few paragraphs
break lines in between them). reason need able re-size text area's borders allow rest of text read. user presented summary paragraph of size , if read more click button , text area opens reveal rest of text. need number of rows multiply font-size can fit of text new text-area, how can find number(the number of rows/lines in paragraph)?
code @ : http://jsfiddle.net/3nmhu/1/ or below -click 'v' bottom-right of text expand text area. -click 'a' bottom-right of text contract text area.
jquery:
$(document).ready(function(){ $('.read_less').hide(); $('.read_more').click(function(){ //confirm($(this).parent().text().length/12); $('.news_item').fadeout('slow'); $(this).parents().fadein('slow'); $(this).hide(); $('.read_less').show('slow'); $(this).parent().animate({height:($(this).parent().text().length/50) *20 + 'px',width:'655px'},'slow'); //$('.bars2').show('slow'); //$('.bars').animate({width:'255px'},'slow'); //$('.bars2').animate({width:'255px'},'slow'); }); $('.read_less').click(function(){ $(this).parent().animate({height:'110px',width:'464px'},'slow'); $('.news_item').fadein('slow'); $('.read_less').hide(); $('.read_more').show(); }); }); i want create these news items each able define it's own expansion space allows text read , text fit in text area snugly , solution needs number of lines.however unsure how find number. moreover, if have better suggestion how remedy error , me solve task @ hand appreciated.
thanks in advance!
one approach take out div's offsetheight , divide it's line-height. give number of lines.
or can use getclientrects() function of javascript, think surely exact thing. function converts every line rectangle can length , number of lines.
Comments
Post a Comment