防止在 pdf 中的空白处拖动文本选择从'jumping'到顶部.js



我正在使用pdf.js与文本选择。

因此,pdf.js 会创建一堆绝对定位的div,其中包含 pdf 中的各种文本以提供文本选择。

拖动以选择文本时,如果继续选择非文本区域(如段落之间的区域),则所选内容将跳转到选择文本顶部的所有内容。

如果你去看他们的例子,你可以看到我在描述什么。尝试在左栏中的几个段落中选择文本,您将看到选择"闪烁"以选择顶部的所有内容。http://mozilla.github.io/pdf.js/web/viewer.html

关于如何防止这种情况发生的任何想法?这非常分散注意力。

我认为这与所有认为文本是绝对的div 有关。

已修复:只需添加高度:200px 到

.textLayer > div {height:200px;}

在查看器中.css

这有点旧,但对某些人来说仍然有用。将 textLayerMode 设置为 2 应该可以解决此问题。

例:

new PDFViewer({ ...otherProps, textLayerMode: 2 })

pdf.js文件中,搜索function appendText并添加

textDiv.className = "hitext";

下面

var textDiv = document.createElement('div');

现在将其添加到您的自定义 js 文件中:

window.addEventListener('mousedown', function mouseup(evt) {
if($(".hitext:hover").length==0) //To check if the cursor is hovering over the text
{
  //Selection is disabled using CSS if the mousedown event was triggered when the cursor was not over the text
  $(".hitext").css({"-webkit-touch-callout": "none", "-webkit-user-select": "none", "-khtml-user-select": "none", "-moz-user-select": "none", "-ms-user-select": "none", "user-select": "none"}); 
}
else 
{
  $(".hitext").css({"-webkit-touch-callout": "text", "-webkit-user-select": "text", "-khtml-user-select": "text", "-moz-user-select": "text", "-ms-user-select": "text", "user-select": "text"}); 
}
});