为什么JavaScript对话框(警告,确认)会停止重绘页面? [英] Why does JavaScript dialog boxes (alert, confirm) stop page redrawing?

查看:102
本文介绍了为什么JavaScript对话框(警告,确认)会停止重绘页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在浏览器页面上打开模式对话框,停止重绘页面。
脚本在后台不间断地开始异步运行。

Opening an modal dialog box on a browser page, stops the page from redrawing. Scripts started asynchronously run uninterrupted in the background.

我在这个JSfiddle中说明了行为 http://jsfiddle.net/YNbux/ 。当显示 alert()时,该框会停止动画,并在警报关闭时跳转到动画中。

I illustrate the behaviour in this JSfiddle http://jsfiddle.net/YNbux/. The box stops its animation when the alert() is shown and jumps in the animation when the alert is closed.

此行为存在于(至少在我的电脑上):

This behaviour is present in (on my computer at least):


  • Chrome 21.0.1180.82

  • Opera 12.01

  • Safari 6.0

所以我猜这是预期的行为 - 但会导致动画跳转,以及其他似乎是最终用户的故障。那么为什么 alert() confirm()停止重绘页面?

So I guess it is intended behaviour - but causes animations to jump, and other things that would seem as glitches to an end user. So why does alert() and confirm() stop pages from redrawing?

修改:
gif-images也停止重绘: http://jsfiddle.net/YNbux/4/

推荐答案

这些函数是阻塞函数。你的JavaScript会一直停止执行,直到它们返回。

Those functions are blocking functions. Your JavaScript stops executing until they return.

你的动画和后台没有的东西与你的代码没有完全分开调用 alert()。看似异步的代码仍然需要在循环中执行,如果某些代码阻塞了循环,它们将不会自行运行。这对正确运行代码至关重要。

Your animations and what not in the background are not completely separated from your code calling alert(). Code that appears to be asynchronous still need to execute in the loop, and if some code blocks that loop, they will not run on their own. This is critical to proper operation of your code.

这篇关于为什么JavaScript对话框(警告,确认)会停止重绘页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆