简体   繁体   English

A框架:如何等待执行,直到图像加载完毕?

[英]A-frame: how can I wait with execution until image is loaded?

I need help. 我需要帮助。 I'm doing some A-frame site and I need it to start only when the image for background is loaded. 我正在做一些A帧网站,仅当加载背景图像时才需要它启动。 The point is the pictures for sphere bacground, that are 360 deg are enormous - like 20000 x 20000 px, so they load for 10 seconds or something. 关键是球面免费图片,它们的360度范围非常大-像20000 x 20000 px,因此它们会加载10秒钟左右。 That depends on the Internet speed. 这取决于互联网的速度。 Ad I don't want my animations to execute before the background is fully loaded (and other images for that matter). 广告我不希望动画在背景完全加载(以及其他图像)之前执行。 Then I added several movements of background, and camera, but by the time the background is loaded - they are all executed. 然后,我添加了背景和相机的一些移动,但是在加载背景时-它们都已执行。 I don't want to download jquery unless it's absolutely necessary. 除非绝对必要,否则我不想下载jquery。 Any ideas? 有任何想法吗?

You could use window.onload to only execute your script once everything in the browser renders. 您可以使用window.onload仅在浏览器中的所有内容呈现后执行脚本。

function myAwesomeAnimationScript() {...}

window.onload = myAwesomeAnimationScript;

Wrap all of your script in a function and simply set a reference to it to handle the event. 将所有脚本包装在一个函数中,然后简单地设置对它的引用以处理该事件。

This is a basic example and will overwrite any other event handler for the specified event, if you want a more elegant solution that respects other handlers look into addEventListener() 这是一个基本示例,如果您想要一个尊重其他处理程序的更优雅的解决方案,请覆盖addEventListener() ,它将覆盖指定事件的任何其他事件处理程序。

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

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