zoukankan      html  css  js  c++  java
  • HTML文本溢出效果

    【前期准备】① 导入jQuery文件;

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>JS-Lamda-Overflow</title>
        <script type="text/javascript" src="js/jquery-1.7.min.js" ></script>
        <style>
            p{padding: 0;margin: 0;}
            .outer{ 300px;height: 80px;line-height: 20px;overflow: hidden;}
        </style>
    </head>
    <body>
        <div class="outer">
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam corporis, 
            	deleniti dolor ducimus error eveniet fuga iusto laborum nisi odio perferendis 
            	reprehenderit sint sit temporibus voluptatibus. Cupiditate exercitationem quis voluptate. 
            	Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam architecto consequatur 
            	dolores error facilis illo odio quis repellendus sed temporibus. Adipisci aliquam ea eaque 
            	esse iste nostrum numquam repellendus rerum! </p>
        </div>
    
        <script>
            $(".outer").each(function(i){
                var outerH = $(this).height();
                var $p = $("p", $(this)).eq(0);
                while ($p.outerHeight() > outerH) {
                    $p.text($p.text().replace(/(s)*([a-zA-Z0-9]+|W)(...)?$/, "..."));
                };
            });
        </script>
    </body>
    </html>
    

    效果显示如下:

  • 相关阅读:
    一. js高级(1)-面向对象编程
    tips01- 定位
    h5c3 part6 flex
    h5c3 part5 background and transform
    template and pagination
    h5c3 part4
    h5c3 part3
    h5c3 part2
    h5c3 part1
    学习博客
  • 原文地址:https://www.cnblogs.com/superdrew/p/9142593.html
Copyright © 2011-2022 走看看