gpt4 book ai didi

javascript - 单击省略号时展开和缩小

转载 作者:行者123 更新时间:2023-12-02 21:53:44 25 4
gpt4 key购买 nike

因此,我的一个小部件中有一个评论部分,我想将其合并为“在省略号上单击,展开和缩小文本”,但我遇到了一些针对以下内容的问题:

  1. 达到一定字数后切断
  2. 单词不与正文包裹在一起。

以下是当前评论的样子:

enter image description here

我的尝试看起来像这样

enter image description here

function RevealHiddenOverflow(d) {
if (d.style.overflow == "hidden") {
d.style.overflow = "visible";
} else {
d.style.overflow = "hidden";
}
}
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<section id="gallery">
<div class="container">
<div id="image-gallery">
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12 image">
<div class="img-wrapper">
<p class="truncate" onclick="RevealHiddenOverflow(this)" style="text-align: center">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
</div>
</div>
</div>
</div>
</section>

最佳答案

您遇到的问题是 white-space: nowrap; 将其强制为一行。您可以像更改可见性一样更改它,或者更好的是,只需在单击时切换类即可删除/添加它。

function RevealHiddenOverflow(d) {
d.classList.toggle("truncate")
}
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<section id="gallery">
<div class="container">
<div id="image-gallery">
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12 image">
<div class="img-wrapper">
<p class="truncate" onclick="RevealHiddenOverflow(this)" style="text-align: center">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
</div>
</div>
</div>
</div>
</section>

关于javascript - 单击省略号时展开和缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60059102/

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