html文字内容溢出,悬停展示全部

第一种方法jstl表达式实现

<td  title="${item.netprobe_nmap_running}">
	<c:choose>
		<c:when test="${fn:length(item.netprobe_nmap_running)>30}">
		${fn:substring(item.netprobe_nmap_running, 0, 30)}...
		</c:when>
		<c:otherwise>${item.netprobe_nmap_running}</c:otherwise>
	</c:choose>
</td>

第二种方法js实现

<div class="content_" style="width:180px;overflow:hidden;
	text-overflow:ellipsis;white-space: nowrap " title="'+data+'">'+data+'</div>


//内容溢出处理:长度固定,溢出部分显示“...”,鼠标悬停展示全部
function bind_content_show(){
	var myTilte ;
	$(".content_").mouseover(function(e){
		var tip = "<div id='tip'style='position:absolute;background-color:#fff;padding:4px 8px;border-radius: 2px;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);'>"+insert_flg(this.title,'<br>',45)+"</div>";
		myTilte = this.title;
		this.title = "";
		$("body").append(tip);
		$("#tip").css({"top":(e.pageY+10)+"px","left":(e.pageX+20)+"px"}).fadeIn("1000");
	}).mouseout(function(){
		this.title = myTilte;
		$("#tip").remove();
	}).mousemove(function(e){
		$("#tip").css({"top":(e.pageY+10)+"px","left":(e.pageX+20)+"px"});
	});
};
//字符串指定位置插入字符串,str表示原字符串变量,flg表示要插入的字符串,sn表示要插入的位置
function insert_flg(str,flg,sn){
    var newstr="";
    for(var i=0;i<str.length;i+=sn){
        var tmp=str.substring(i, i+sn);
        newstr+=tmp+flg;
    }
    return newstr;
}

Vue 可以通过 CSS 和内置指令 v-text-overflow 来实现文字溢出后点击省略号展示更多的效果。 首先,可以定义一个包含溢出文本的容器,并限制其宽度和高度,使得文本溢出时可以产生省略号。例如: ```html <div class="text-container"> {{ longText }} </div> ``` 然后,通过 CSS 样式来设置溢出文本的省略号和点击展示更多的特效: ```css .text-container { overflow: hidden; /* 溢出内容隐藏 */ text-overflow: ellipsis; /* 显示省略号 */ white-space: nowrap; /* 不换行 */ width: 200px; /* 容器宽度 */ height: 20px; /* 容器高度 */ } .text-container:hover { overflow: visible; /* 鼠标悬停展示全部内容 */ height: auto; /* 自动调整高度以完整显示文本 */ } ``` 最后,在 Vue 中使用 v-text-overflow 指令将文本绑定到容器中,并通过鼠标事件来切换展示状态: ```html <div class="text-container" v-text-overflow="longText"></div> ``` ```javascript Vue.directive('text-overflow', { inserted: function (el, binding) { el.textContent = binding.value; el.addEventListener('mouseover', function () { el.style.overflow = 'visible'; el.style.height = 'auto'; }); el.addEventListener('mouseleave', function () { el.style.overflow = 'hidden'; el.style.height = '20px'; }); }, }); ``` 通过以上代码,在文本溢出时,鼠标悬停在容器上时将展示全部文本,移开鼠标时将再次显示省略号。这样,就实现了通过点击省略号展示更多文本的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值