1.一般情况下,想要实现文本超过几行后显示省略号的css。

color: #101010;
font-size: 14px;
text-align: justify;
font-family: SourceHanSansSC-regular
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;

2.但是有兼容性问题,就是在苹果手机时省略号会和内容重叠

3.解决的方法有几个,下面说2种,

3.1 方法简单,但如果内容有中英文的话,省略号显示的位置可能会不一样。

( (屏幕宽度-内容距离屏幕宽度两边的总和)/字体大小)*行数-预留给省略号的长度

window.contentMaxLength = (($(window).width() - 60) / 14) * 3 - 3;

然后获取获取内容的长度再判断一下是否大于计算好的长度进行截取
var conValue = resData.records[i].conValue;if (conValue && conValue.length > contentMaxLength) {    resData.records[i].conValue = conValue.substr(0, contentMaxLength) + ' ...';}

3.2 使用jq提供的ellipsis.js(自动计算内容宽度截断,并加上省略号,内容不受中英文或符号限制)
demo+链接地址: https://github.com/thinhunan/jquery.ellipsis.js

3.3 借鉴修改后的ellipsis.js
(function($) {    $.fn.ellipsis = function(options) {

        // default option        var defaults = {            'row' :3, // show rows            'onlyFullWords': false, // set to true to avoid cutting the text in the middle of a word            'char' : '...', // ellipsis            'callback': function() {},            'position': 'tail' // middle, tail        };

        options = $.extend(defaults, options);

        this.each(function() {            // get element text            var $this = $(this);            var text = $this.text();            var origText = text;            var origLength = origText.length;            var origHeight = $this.height();

            // get height            $this.text('a');            var lineHeight =  parseFloat($this.css("lineHeight"), 10);            var rowHeight = $this.height();            var gapHeight = lineHeight > rowHeight ? (lineHeight - rowHeight) : 0;            var targetHeight = gapHeight * (options.row - 1) + rowHeight * options.row;

            if (origHeight <= targetHeight) {                $this.text(text);                options.callback.call(this);                return;            }

            var start = 1, length = 0;            var end = text.length;

            if(options.position === 'tail') {                while (start < end) { // Binary search for max length                    length = Math.ceil((start + end) / 2);

                    $this.text(text.slice(0, length) + options['char']);

                    if ($this.height() <= targetHeight) {                        start = length;                    } else {                        end = length - 1;                    }                }

                text = text.slice(0, start);

                if (options.onlyFullWords) {                    text = text.replace(/[\u00AD\w\uac00-\ud7af]+$/, ''); // remove fragment of the last word together with possible soft-hyphen characters                }                text += options['char'];

            }else if(options.position === 'middle') {

                var sliceLength = 0;                while (start < end) { // Binary search for max length                    length = Math.ceil((start + end) / 2);                    sliceLength = Math.max(origLength - length, 0);

                    $this.text(                        origText.slice(0, Math.floor((origLength - sliceLength) / 2)) +                        options['char'] +                        origText.slice(Math.floor((origLength + sliceLength) / 2), origLength)                    );

                    if ($this.height() <= targetHeight) {                        start = length;                    } else {                        end = length - 1;                    }                }

                sliceLength = Math.max(origLength - start, 0);                var head = origText.slice(0, Math.floor((origLength - sliceLength) / 2));                var tail = origText.slice(Math.floor((origLength + sliceLength) / 2), origLength);

                if (options.onlyFullWords) {                    // remove fragment of the last or first word together with possible soft-hyphen characters                    head = head.replace(/[\u00AD\w\uac00-\ud7af]+$/, '');                }

                text = head + options['char'] + tail;            }

            $this.text(text);

            options.callback.call(this);        });

        return this;    };}) (jQuery);
页面调用:$(dom).ellipsis();


-webkit-line-clamp 兼容性问题的更多相关文章

  1. css自动省略号...,通过css实现单行、多行文本溢出显示省略号

    网页开发过程中经常会遇到需要把多行文字溢出显示省略号,这篇文章将总结通过多种方法实现文本末尾省略号显示. 一.单行文本溢出显示省略号(…) 省略号在ie中可以使用text-overflow:ellip ...

  2. Atitit.html css  浏览器原理理论概论导论attilax总结

    Atitit.html css  浏览器原理理论概论导论attilax总结 1.1. 浏览器是怎样工作的:渲染引擎,HTML解析(连载二)1 2. 5.1.1 DOM标准 1011 3. <We ...

  3. Swiper之滑块1

    之前介绍过Swiper,它是一个神奇的插件.类似于Android的触屏操作,Swiper应用于Web中也可以实现这样的效果,我们来看看(用鼠标可拖动). startSlide Integer (def ...

  4. HTML5/CSS3 第三章页面布局

    页面布局 1 页面组成 2 布局相关的标签 <div></div> 定义文档中的分区或节 <span></span> 这是一个行内元素,没有任何意义 & ...

  5. "android.uid.systemandroid.view.InflateException: Binary XML file line #7: Error inflating class android.webkit.WebView

    在android源码中编译app通过,运行时出现错误: "android.uid.systemandroid.view.InflateException: Binary XML file l ...

  6. IE兼容性问题汇总【持续更新中】

    问题:IE8/9不支持Array.indexOf 解决方案 if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt ...

  7. [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析

    [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析 标签: webkit内核JavaScriptCore 2015-03-26 23:26 2285 ...

  8. 微信浏览器是移动端的IE6?微信升级内核后Html5和CSS3兼容性总结

    今年4月,自从微信浏览器X5 升级Blink内核之后,各前端社区一片高潮,仿佛看到了前端er,眼含热泪进而抱头痛头的说:终于可以不用兼容这"移动端的IE6 "了,可以早点回家了!! ...

  9. CSS3与页面布局学习笔记(八)——浏览器兼容性问题与前端性能优化方案

    一.浏览器兼容 1.1.概要 世界上没有任何一个浏览器是一样的,同样的代码在不一样的浏览器上运行就存在兼容性问题.不同浏览器其内核亦不尽相同,相同内核的版本不同,相同版本的内核浏览器品牌不一样,各种运 ...

  10. 解决webkit浏览器中js方法中使用window.event提示未定义的问题

    这实际上是一个浏览器兼容性问题,根源百度中一大堆,简要说就是ie中event对象是全局变量,所以哪里都能使用到,但是webkit内核的浏览器中却不存在这个全局变量event,而是以一个隐式的局部变量的 ...

随机推荐

  1. GitLab Pages expect to run on their own virtual host

    GitLab Pages administration | GitLab https://docs.gitlab.com/ce/administration/pages/

  2. In Git, there are two main ways to integrate changes from one branch into another: the merge and the rebase.

    https://git-scm.com/book/en/v2/Git-Branching-Rebasing

  3. 解决表单GET提交后台数据乱码问题

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/ForeverCjl/article/details/36180933     ​在页面上提交数据到s ...

  4. (转)基于RTP的H264视频数据打包解包类

    最近考虑使用RTP替换原有的高清视频传输协议,遂上网查找有关H264视频RTP打包.解包的文档和代码.功夫不负有心人,找到不少有价值的文档和代码.参考这些资料,写了H264 RTP打包类.解包类,实现 ...

  5. cc、gcc、g++区别

    gcc是C编译器:g++是C++编译器:linux下cc一般是一个符号连接,指向gcc:gcc和g++都是GUN(组织)的编译器.而CC则一般是makefile里面的一个名字,即宏定义,嘿,因为Lin ...

  6. windows定时计划备份MySql

    使用 MySql 的 mysqldump 将数据库文件备份成 sql 文件. Windows下备份 本地的数据库环境 MySql 安装环境:C:\MySql 数据库名称:bbs root root 数 ...

  7. android——array中设置选项

    Android中,R.array是提取XML资源文件中String数组的方法.具体定义和提取的方法如下: 1)在R.array中定义字符数组 <?xml version="1.0&qu ...

  8. POJ2559 Largest Rectangle in a Histogram —— 单调栈

    题目链接:http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Lim ...

  9. HTML5 Canvas 自定义笔刷

    1. [图片] QQ截图20120715095110.png ​​2. [代码][HTML]代码 <!DOCTYPE html><html lang="en" & ...

  10. YCSB-mapkeeper

    首先 https://github.com/brianfrankcooper/YCSB/issues/885 最终是使用ycsb-0.1.4 版本进行,这个版本自带jar包 https://githu ...