2012-01-03 2 views
0

div에 내용이 표시되는 데 문제가 있습니다. 일부 텍스트는 div에 표시해야하는 내용의 10 줄을 고려해야합니다. 처음에는 div에 2 줄의 내용 만 표시하고, &에는 하나의 링크 "읽기 완료"가 표시되도록 디자인하고 싶습니다. & 링크를 클릭하면 전체 내용이 표시되어야합니다. & 링크를 "숨기기"로 변경해야합니다. & 다시 숨기기 링크를 클릭하면 2 줄의 내용 만 다시 표시해야합니다.두 줄까지만 div 내용 표시

제발 도와주세요.

업데이트 : 콘텐츠 콘텐츠의 끝 @ 두 라인의 경우는 3 점 (...)

+1

. 그러나 운이 없다. –

+1

왜 운이 아니니? 그렇지 않니? –

+1

아니요 ... 사실 제가해야 할 방식대로 할 수는 없습니다. –

답변

2

나는이 당신에게

<div id="mydiv"> 
Please read the documentation. 
For updates please follow our blog, tweets or become a fan. 
    <span><a href="#" id="more" onclick="full_view(this.id)">more</a></span> 
<span style="display:none;" id="disMore"><p>Please read the documentation.  
For updates please follow our blog, tweets or become a fan.Please read the documentation. 
For updates please follow our blog, tweets or become a fan.Please read the documentation. 
For updates please follow our blog, tweets or become a fan.</p></span> 
<span><a href="#" id="hide" onclick="half_view(this.id)" style="display:none;">hide</a></span> 
</div> 

자바 스크립트가 도움이되기를 바랍니다 : 나는 DIV 높이 증가 감소 노력했다

function full_view(e) { 
document.getElementById('disMore').style.display = "block"; 
document.getElementById('more').style.display = "none"; 
document.getElementById('hide').style.display = "block"; 
} 
function half_view(e) { 
document.getElementById('disMore').style.display = "none"; 
document.getElementById('more').style.display = "block"; 
document.getElementById('hide').style.display = "none"; 
} 
+1

사실 저는 dynamicType을 서블릿에서 String 유형으로 사용하고 있습니다. –

+0

동적 콘텐츠 란 질문에 언급하시기 바랍니다. –

0

당신은 이런 식으로 작업을 수행 할 수 있습니다 :

<div id="text"> 
    Your content... 
</div> 

<a href="#" id="readall">Read all</a> 

$(document).ready(function() { 
    //Change this variable to show more or less lines: 
    var nrOfLines = 2; 
    var height = 0; 

    //Get line height 
    height = $('div#text').css('line-height'); 
    height = height.substring(0, height.search('px')); 
    height = (height * nrOfLines) + 'px'; 
    //Set div to only show 2 lines 
    $('div#text').css({'height' : height}); 

    setTriggers(); 

    function setTriggers() { 
     $('a#readall').click(function() { 
      $(this).attr('id', 'hide'); 
      $(this).html('Hide'); 
      $('div#text').css({'height' : 'auto', 
           'overflow' : 'auto'}); 
      setTriggers(); 
     }); 

     $('a#hide').click(function() { 
      $(this).attr('id', 'readall'); 
      $(this).html('Read all'); 
      $('div#text').css({'height' : height, 
           'overflow' : 'hidden'}); 
      setTriggers(); 
     }); 
    } 

}); 

그리고 당신의 CSS : http://jsfiddle.net/c5sza/2/

:

div#text { 
    border: 1px solid black; 
    width: 250px; 
    overflow: hidden; 
} 

를 내가 여기 예를 만들어 여기 jsfiddle 내 간단한 데모입니다 슬라이딩 효과 등을 사용하여 더 포주 수 있습니다.

+1

글꼴 크기가 커지면 작동하지 않습니다. –

+1

이 플랫폼의 목표는 당신에게 완벽한 기능의 솔루션을 제공하는 것이 아니라 (개발자를 고용하고 그에 대한 대가를 지불하는 것), 어떻게해야하는지에 대한 아이디어를 제공하는 것입니다. 이것은 귀하의 질문에 대한 완벽한 대답입니다. 이제는 사용자의 요구에 맞게 향상시켜야합니다. – Jules

+1

나는 그 친구를 안다. 그러나 나는 새로운 2 js n css 물건입니다. –