您好,我尝试在我的网站中实现 subj 插件。
我用下一行代码在外部文件上测试了这个插件(插件非常快:
%iframe{src: '/pdfjs/web/viewer.html?file=http://cdn.mozilla.net/pdfjs/tracemonkey.pdf', style:'border: 0', width:'100%', height:'100%', frameborder:'0', scrolling:'no'}
但是当我实现自己的文件时(在元素中我自己的文件夹中) 这个插件变得很慢。
%iframe{src: '/pdfjs/web/viewer.html?file=/system/uploads/deal/download_document/24/aaaaa/some.pdf', style:'border: 0', width:'100%', height:'100%', frameborder:'0', scrolling:'no'}
截图
左图:外部(快速)文件的时间轴(1271 个元素为 35 毫秒)
右图:内部(慢速)文件的时间轴(7737 个元素为 196 毫秒):
最佳答案
此性能下降是由 grab-to-pan.js 引起的,我为 PDF.js 编写的库,用于实现手形工具功能。按下鼠标时,库会切换 <html>
上的类名元素,通过 CSS 更改光标(从“抓取”到“抓取”):
.grab-to-pan-grabbing * {
cursor: url("grabbing.cur"), move !important;
cursor: -webkit-grabbing !important;
cursor: -moz-grabbing !important;
cursor: grabbing !important;
}
这个方法貌似对性能有很大的影响,所以我改变了更新游标的方式。参见 https://github.com/Rob--W/grab-to-pan.js/commit/e0f893753ac10a5c97159fd01155b05d234f4c0f对于变化。一些测试表明,新方法的速度提高了 100 多倍。我已将补丁提交给 PDF.js PR #4209 .
关于css - 性能问题 : Recalculating Styles takes 200ms in PDF. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21392844/