jQuery 在 p 内遍历
所以我在使用 jQuery 时遇到了问题。
基本上,我需要创建一个函数,当段落对于容器来说太大时,该函数将分割段落。其中一半将保留在当前容器中,其余的将下降到下一个容器中。
基本上我想逐行浏览文本,测试它的高度以及它上面的所有行。有没有办法遍历段落的行?
另外,在调整大小时,我会将其绑定到侦听器,以便当宽度更改时,每个元素中的内容仍然保持相同的高度。
我希望这一切都有道理!
So I'm having a problem with some jQuery.
Basically, I need to create a function that will split a paragraph, when it becomes too large for a container. Half of it will remain in the current container, and the rest will drop down to the next.
Basically I want to go line by line through the text, testing the height of it and all lines above it. Is there a way to traverse through lines of a paragraph?
Also, on resize I will have this bound to a listener so that when the width changes, the content still remains the same height in each element.
I hope that all made sense!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为你可以在一个段落中浏览“行”,因为视觉上看起来像 10 行的内容实际上可能只是一个换行符(没有实际的换行符)。
例如,您可以将
overflow
设置为在容器上显示,并使用height/clientHeight
检测何时发生溢出,然后通过计算字数或类似内容来分割文本。更新:
这是一个演示:http://jsfiddle.net/AQwFM/4/ 显然需要改进
,但应该可以帮助您入门。
I don't think you can go through "lines" in a paragraph, because what may visually seem like 10 lines could actually be only one wrapped line (no actual line breaks).
You could, for example, set the
overflow
to show on the container, and detect when the overflow happens withheight/clientHeight
, and then split the text by counting words or similar.UPDATE:
Here is a demo: http://jsfiddle.net/AQwFM/4/
Obviously need improvements, but should get you started.