javascript非阻塞图像加载?
这个函数每 30 毫秒调用一次
function draw(){
context.clearRect(0, 0,canvas.width, canvas.height);
context.drawImage(displayme, plot.position.x, plot.position.y, plot.width, plot.height);
}
,一些鼠标事件会修改 displayme.src 和绘图位置,
但是当加载新的 src 时,所有其他 javascript 都会被阻止并且无法移动(之前加载的)图像
我也尝试过使用不同的图像对象并将其分配给“displayme”,但它不起作用
任何帮助将是最受欢迎的
this function is called every 30ms
function draw(){
context.clearRect(0, 0,canvas.width, canvas.height);
context.drawImage(displayme, plot.position.x, plot.position.y, plot.width, plot.height);
}
and some mouse events modify the displayme.src and plot position
but when the new src is being loaded, all the other javascript gets blocked and cant move the (previously loaded) image
i've also tried using a different Image object and assigning it to "displayme" but it didn't work
any help would be most welcome
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK 所有浏览器都在单个线程中运行 javascript。您可以使用
setTimeout()
使该函数立即返回,但在该函数实际运行时,浏览器不会在页面上运行任何其他 JavaScript。这模拟了多线程,但不应将其误认为是真实的。AFAIK all browsers run javascript in a single thread. You can, using
setTimeout()
make it so this function returns immediately, but at the time that the function actually runs the browser won't be running any other javascript on the page. This simulates multithreading, but it shouldn't be mistaken for the real thing.