在 pdf.js 中拖动空格时防止文本选择“跳”到顶部

B. *_*ell 8 javascript pdf pdf.js

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

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

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

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

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

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

Vin*_* RJ 0

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

textDiv.className = "hitext";
Run Code Online (Sandbox Code Playgroud)

以下

var textDiv = document.createElement('div');
Run Code Online (Sandbox Code Playgroud)

现在将其添加到您的自定义 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"}); 
}

}); 
Run Code Online (Sandbox Code Playgroud)