-webkit-line-clamp 兼容性问题
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 兼容性问题的更多相关文章
- css自动省略号...,通过css实现单行、多行文本溢出显示省略号
网页开发过程中经常会遇到需要把多行文字溢出显示省略号,这篇文章将总结通过多种方法实现文本末尾省略号显示. 一.单行文本溢出显示省略号(…) 省略号在ie中可以使用text-overflow:ellip ...
- Atitit.html css 浏览器原理理论概论导论attilax总结
Atitit.html css 浏览器原理理论概论导论attilax总结 1.1. 浏览器是怎样工作的:渲染引擎,HTML解析(连载二)1 2. 5.1.1 DOM标准 1011 3. <We ...
- Swiper之滑块1
之前介绍过Swiper,它是一个神奇的插件.类似于Android的触屏操作,Swiper应用于Web中也可以实现这样的效果,我们来看看(用鼠标可拖动). startSlide Integer (def ...
- HTML5/CSS3 第三章页面布局
页面布局 1 页面组成 2 布局相关的标签 <div></div> 定义文档中的分区或节 <span></span> 这是一个行内元素,没有任何意义 & ...
- "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 ...
- IE兼容性问题汇总【持续更新中】
问题:IE8/9不支持Array.indexOf 解决方案 if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt ...
- [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析
[WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析 标签: webkit内核JavaScriptCore 2015-03-26 23:26 2285 ...
- 微信浏览器是移动端的IE6?微信升级内核后Html5和CSS3兼容性总结
今年4月,自从微信浏览器X5 升级Blink内核之后,各前端社区一片高潮,仿佛看到了前端er,眼含热泪进而抱头痛头的说:终于可以不用兼容这"移动端的IE6 "了,可以早点回家了!! ...
- CSS3与页面布局学习笔记(八)——浏览器兼容性问题与前端性能优化方案
一.浏览器兼容 1.1.概要 世界上没有任何一个浏览器是一样的,同样的代码在不一样的浏览器上运行就存在兼容性问题.不同浏览器其内核亦不尽相同,相同内核的版本不同,相同版本的内核浏览器品牌不一样,各种运 ...
- 解决webkit浏览器中js方法中使用window.event提示未定义的问题
这实际上是一个浏览器兼容性问题,根源百度中一大堆,简要说就是ie中event对象是全局变量,所以哪里都能使用到,但是webkit内核的浏览器中却不存在这个全局变量event,而是以一个隐式的局部变量的 ...
随机推荐
- 关于java的线程
1 java的线程也是一个对象 所以,java线程对象也是由gc销毁的. 2 java线程对象等待被销毁的时机 当java线程执行完run()方法之后就在等待被销毁了,所以要一个线程对象不被销毁唯一的 ...
- esri和ArcGIS
1 esri esri是environment system research institute,环境系统研究所.总部在美国加州.它是世界上最大的GIS技术提供商. 主要产品有ArcGIS.ArcV ...
- 简单实现php文件管理
如何能够利用PHP语言来进行空间中的文件管理,为我们带来良好的空间布局呢?今天我们就为大家介绍一种简便的PHP文件管理的实现方法. PHP预定义变量数组种类概览 PHP uploaded_files函 ...
- mapkeeper总结
1. mapkeeper下有个thrift目录,在该目录编译c++版本和java版本. C++版本需要系统安装thrift-0.9.2,而java版本需要系统安装thrift-0.8.0 2. thr ...
- ORA-32001:write to SPFILE requested but no SPFILE is in use
oracle报错: ORA-32001:write to SPFILE requested but no SPFILE is in use 解决方法: 1.查看是否有spfile sql> sh ...
- OJ提交题目中的语言选项里G++与C++的区别
一.OJ提交题目中的语言选项里G++与C++的区别 http://www.th7.cn/Program/cp/201405/199001.shtml 首先更正一个概念,C++是一门计算机编程语言,G+ ...
- 关于内存DC
使用CreateCompatibleDC 创建了内存DC之后,要再调用SelectObject选择一张位图放入此DC,然后才可以使用此DC进行绘制,之后绘制的数据会保存在内存中, 详细说明看后文. 在 ...
- liunx目录/etc下相关配置
这些都是比较有实用性的系统配置,收藏下,以备不时之需!以下是etc下重要配置文件解释: 1./etc/hosts #文件格式: IPaddress hostname aliases #文件功能: 提 ...
- TwinCAT3提示找不到TcPch.h错误解决
我使用git对TwinCAT3的工程进行版本控制,但是别的电脑clone的仓库会提示找不到TcPch.h的错误,无法编译. 明明文件就在那里,就是不让编译... 解决办法更奇葩,只需要把工程文件压缩, ...
- C - Bear and Five Cards
Description A little bear Limak plays a game. He has five cards. There is one number written on each ...