简体   繁体   English

HTML5 Canvas在完成渲染时会发出事件吗?

[英]Does HTML5 Canvas emit an event when it finishes rendering?

I'm having a problem right now with mobile browsers, trying to use PDF.JS to render PDF files in the browser. 我现在遇到移动浏览器的问题 ,试图使用PDF.JS在浏览器中呈现PDF文件。 It works fine, but I need to render a gradient over the PDF files to hide some of the content, and I don't know how to figure out when the canvas is done rendering the PDF, so I'm setting a 3 second time-out and then running my "callback". 它工作正常,但我需要在PDF文件上渲染一个渐变来隐藏一些内容,我不知道如何弄清楚画布何时渲染PDF,所以我设置了3秒钟-out然后运行我的“回调”。 It's not pretty, and I think it might be the cause of the problem above, since: 它不漂亮,我认为它可能是上述问题的原因,因为:

  • the issue doesn't happen on desktop browsers at all. 这个问题根本不会发生在桌面浏览器上。
  • the issue doesn't happen on mobile if I don't render the gradient. 如果我不渲染渐变,问题不会发生在移动设备上。

So my conclusion is that for some weird reason, if the gradient gets rendered before the PDF is finished rendering, the canvas "freaks out". 所以我的结论是,出于一些奇怪的原因,如果渐变在PDF完成渲染之前被渲染,那么画布“吓坏了”。

So, I need to attach a callback to the viewer's rendering operation, really, but I seriously doubt that such a function exists within this poorly documented (but mostly great-working) library. 所以,我需要将一个回调附加到查看器的渲染操作,实际上,但是我非常怀疑这个功能是否存在于这个记录不完整(但大多数工作很好)的库中。

Does HTML5 Canvas emit an event when it finishes rendering? HTML5 Canvas在完成渲染时会发出事件吗? If not, is there any solution that might allow me to ensure that the canvas's rendering is complete? 如果没有,是否有任何解决方案可以让我确保画布的渲染完成?

No, it does not. 不,不是的。
The canvas or it context doesn't have a clue what's actually happening to (/being drawn on) them. 画布或它的上下文并不知道它们实际发生了什么(正在被绘制)。

You're going to have to "attach a callback to the viewer's rendering operation." 您将不得不“将回调附加到查看器的渲染操作”。

Just for reference, it turns out that I was wrong, and (I think this was a recent change?) the PDF JS library is hosted by and integrated natively by Mozilla. 仅供参考,事实证明我错了,(我认为这是最近的变化?)PDF JS库由Mozilla本地托管和集成。 So naturally, they are on top of that API with features for just about everything (albeit in a documentation "format" meant more for experienced software engineers, in code form) and the way to attach an event handler for the page's rendering operation completion is implimented here: 很自然地,他们在API之上,几乎所有东西都有功能(虽然文档“格式”对于经验丰富的软件工程师来说更多,代码形式更多),并且为页面的渲染操作完成附加事件处理程序的方法是这里称赞:

https://github.com/mozilla/pdf.js/blob/master/web/pdf_viewer.js#L225 https://github.com/mozilla/pdf.js/blob/master/web/pdf_viewer.js#L225

and accessed here: 并访问:

https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L1733 https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L1733

An event, pagerendered , is fired. pagerendered一个已pagerendered的事件。

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

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