gpt4 book ai didi

javascript - chop 文本并根据需要恢复它

转载 作者:行者123 更新时间:2023-12-01 04:05:30 28 4
gpt4 key购买 nike

My Codepen

if("matchMedia" in window) {
if(window.matchMedia("(max-width: 533px)").matches) {
$('.title').each(function() {
var theContent = $(this).text();
if (theContent.length >= 35) {
var n = theContent.substring(0, 35);
$(this).html(n + '...');
}
});
} else {
// ??
}
}

你好,

我必须创建一个函数,必须确保在传递移动分辨率时 chop 太大的文本。第一部分( chop )有效,但当分辨率超过 533px 时,我无法完成它以恢复页面上的所有标题。

有人可以给我一首歌吗?或者如果有更好的可以给我一个更好的方法吗?

非常感谢。

最佳答案

纯 CSS 怎么样?

.title {
width: 50%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<div class="title">
I am a somewhat long title, that will not fit on all screens
</div>

关于javascript - chop 文本并根据需要恢复它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41860617/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com