繁体   English   中英

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

[英]Prevent text selection from 'jumping' to top when dragging over whitespace in pdf.js

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

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

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

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

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

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

固定:只需添加高度:200px

.textLayer > div {height:200px;}

在viewer.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"}); 
}

}); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM