如何判断一个< div>是充满文本? [英] How can you tell when a <div> is full of text?

查看:107
本文介绍了如何判断一个< div>是充满文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一个具有元素的网站

网站想要运行一些JS,它将用随机文本填充div,当div满时,应该清除并重新开始。是的,我知道听起来很奇怪,但问题是,JS如何知道当div是满的,并将开始溢出?

Imagine a website with an element The site wants to run some JS which will fill the div with random text, when the div is full it should clear and start over. Yes I know that sounds weird but the question is, how can the JS know when the div is full, and would start to overflow?

由'full',我的意思是没有更多的可见文本可以放在div。我想这是一个滚动条将被启用/可见的点。

By 'full', I mean no more visible text can be put in the div. I suppose this is the point a scroll bar would become enabled/visible.

推荐答案

你可以做的是,文本在内部div,具有与容器相同的固定宽度,但没有固定的高度。然后,让内部div随其内容增长,并检查其高度接近父div的固定高度

What you could do would be to actually have the text in an inner div, that has the same fixed width as the container, but no fixed height. You'd then let the inner div grow with its content, and check when its height approaches the parent div's fixed height

这篇关于如何判断一个< div>是充满文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆