简体   繁体   English

Javascript / jQuery:检查文本是否在元素的视口内

[英]Javascript/jQuery: Check if text is within viewport of element

I have text within an element whose font size is font-size: 4vw , this means that if the text is too long, only the beginning of the text will remain within the viewport. 我在字体大小为font-size: 4vw的元素中包含文本,这意味着如果文本太长,则仅文本的开头将保留在视口中。

eg: |Example Long Text| 例如:||长文本示例| becomes |Example Lon|. 成为| Example Lon |。 I'm looking to write a script such that rather than do that, it will become |Example L..| 我希望编写一个脚本,而不是那样做,它将成为| Example L .. |。 to indicate that there is more content. 表示还有更多内容。 However, I don't know how to check if the text has left the viewport. 但是,我不知道如何检查文本是否已离开视口。

Any ideas? 有任何想法吗?

You don't have to use JS to solve this - it can be done with pure CSS using the text-overflow property. 您不必使用JS来解决此问题-可以使用纯CSS使用text-overflow属性来完成此任务。 This saves you from having to work out some of the complexities of coding this yourself. 这使您不必自己编写一些复杂的代码。

Example here: https://jsfiddle.net/37x7jyze/ 此处的示例: https//jsfiddle.net/37x7jyze/

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

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