jQuery多余文字折疊效果


CSS代碼

 1 .morecon{ 
 2     cursor:pointer;
 3     font-size:14px; float: left;
 4     margin: 5px 10px 0 0;
 5     color: #0096FF;
 6 }
 7 .checkmore .text{
 8     width: 100px;
 9     overflow: hidden;
10 }

HTML代碼

1 <div class="checkmore">
2     <div class="text">
3         <p>我是愛德華,來自美國舊金山,會英語,德語,法語,畢業於加你福尼亞大學;
4             我是愛德華,來自美國舊金山我是愛德華,來自美國舊金山,會英語,德語,法語,畢業於加你福尼亞大學;
5         </p>
6     </div>
7 </div>

JS代碼

 1 <script src="static/js/jquery-3.1.1.min.js"></script>
 2 <script type="text/javascript">
 3     $(document).ready( function() {
 4         $(".checkmore .text").each(function(){
 5             height=$(this).height();
 6             if(height>88) {
 7                 $(this).css("height","88");
 8                 $(this).after("<a class=\"morecon\" >查看更多</a>");
 9             }
10         });
11         $(".morecon").click(function(){
12             $(this).parent().children(".text").css("height","auto");
13             $(this).css("display","none");
14         });
15     });
16 </script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM