简体   繁体   English

弹出超过一定长度的段落

[英]Popup for paragraphs exceeding a certain length

I am working on a website that has dynamically generated blog posts that can have any length. 我正在一个网站上动态生成可以任意长度的博客文章。 I would like to limit the height of each blog post entry to a certain height, let's say 250px. 我想将每个博客文章条目的高度限制为一定的高度,例如250px。 If a blog post's content exceeds that height, I would like to cut it off and display a "read more" link which will open a modal overlay within which the entire post is displayed. 如果博客文章的内容超过该高度,我想将其截断并显示“阅读更多”链接,该链接将打开一个模式叠加层,其中将显示整个帖子。

I am using standard html/css/js for all front end view development. 我正在为所有前端视图开发使用标准html / css / js。

My question is if there is a tool out there that does this out of the box. 我的问题是,是否有工具可以立即使用。 I found and have used http://jedfoster.com/Readmore.js/ in the past but it doesn't open a popup modal overlay. 我发现并过去使用过http://jedfoster.com/Readmore.js/ ,但是它没有打开弹出式模式叠加层。 Is there something similar readmore.js that opens an overlay? 是否有类似的readmore.js可以打开覆盖图?

The way I would do this is to test your scrollHeight against the client height.. here's an example: 我这样做的方法是针对客户端高度测试您的scrollHeight ..这是一个示例:

This will alert "YES": 这将提示“是”:

<div id="overflow-test" style="height:250px;width:100px;overflow-y:hidden;">
   Lorem ipsum dolor sit amet, consectetur adipisicing 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.
</div>

<script>
alert($('#overflow-test')[0].scrollHeight > $('#overflow-test').height() ? "YES" : "NO");
</script>

This will alert "NO": 这将提示“否”:

<div id="overflow-test" style="height:250px;width:100px;overflow-y:hidden;">
   Lorem ipsum dolor sit amet.
</div>

<script>
alert($('#overflow-test')[0].scrollHeight > $('#overflow-test').height() ? "YES" : "NO");
</script>

Basically, I would test them with a $.each() and make the read more button visible and enabled if they extend beyond the height of the div, and add code to use a modal box if the button is enabled and it tests as beyond the visible portion of the div. 基本上,我将使用$ .each()对其进行测试,如果它们超出了div的高度,则将使更多阅读按钮可见并启用,如果按钮已启用且测试超出,则添加代码以使用模式框div的可见部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM