2014-07-08 2 views
-1

나는이 멋진 플러그인을 사용하고 있으며 첫 번째 항목을 열어 놓고 나머지는 닫을 수있는 방법을 알고 싶습니다.readmore javascript plugin first item open

아이디어가 있으십니까?

자바 스크립트

var options = { 
      moreLink: '<a class="read_more_link" href="#">more...</a>', 
      lessLink: '<a class="read_less_link" href="#">less...</a>', 
      heightMargin: 50, 
      sectionCSS: 'display: inline-block; width: 100%;', 
     }; 

    $('.content-top-wide, .content-bottom-item').each(function(){ 
     var el = $(this), content = el.find('div:first,span:first,p:first, article:first'), maxHeight = 0; 
     if (content.length) { 
      maxHeight = content.outerHeight(); 
      content.prevAll().each(function(){ 
       maxHeight += $(this).outerHeight(true); 
      }); 
      // set maxHeight to 200px if the element has hight greater than 200 
      options.maxHeight = Math.min(200, maxHeight); 
      el.readmore(options); 
     }; 
    }); 

HTML

<div class="content-bottom pull-left"> 
    <h2>Title</h2> 
    <div class="content-bottom-item pull-left"> 
     Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus, consequatur inventore iure aliquam praesentium molestiae facilis labore! Magni, dolorem, ex? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus, consequatur inventore iure aliquam praesentium molestiae facilis labore! Magni, dolorem, ex? 
    </div> 
</div> 

답변

0

플러그인의 설명서를 읽어 https://github.com/jedfoster/Readmore.js를?
첫 번째 항목의 옵션에 "startOpen : false"를 추가하면 문제가 해결됩니다. 내가 if 문 추가하여 이렇게 관리되는

+0

하고 내가 노력하고 정확히 : 여기

if (i == 0) { options.startOpen = true; } else { options.startOpen = false; } el.readmore(options); 

사례 사람의 작업 버전이 필요하다 방법을 알기 - 첫 번째 항목의 옵션에 "startOpen : false"를 추가합니다. 설명서에는 startOpen : false를 모든 항목에 추가하는 방법이 설명되어 있지만 처음 항목에는 포함되지 않습니다. – brunodd