gpt4 book ai didi

javascript - 如何在滚动的 DIV 中获取当前事件文本

转载 作者:技术小花猫 更新时间:2023-10-29 12:42:08 25 4
gpt4 key购买 nike

包含需要滚动条的段落的碎裂 DIV

例如

<div id="text" style='overflow:scroll;width:200px;height:200px'>

<div style='font-size:64px;'>BIG TEXT</div>
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and scrambled it
to make a type specimen book. It has survived not only five centuries, but also
the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop publishing software
like Aldus PageMaker
including versions of Lorem Ipsum.

</div>

当滚动条移动时,文本发生变化(由于overflow:scroll),是否可以只选择当前视口(viewport)显示的文本?

示例:http://jsfiddle.net/cxgkY/15/

更新:内部 HTML 可能包含可变大小的文本

最佳答案

这里有一个小演示,可以满足您的期望:little link (也适用于可变尺寸)。这个想法是为每个单词自动创建一个单独的 span,然后,每次滚动 div 时,检查哪些 span 是可见的(通过检查它们的 top 偏移量),从而更新文档选择范围。如果有什么不清楚,我很乐意解释。

关于javascript - 如何在滚动的 DIV 中获取当前事件文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12120788/

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