Javascript事件循环堆栈和加载外部CSS的顺序是什么?

时间:2017-04-05 02:57:32

标签: javascript html css event-loop

假设我有以下代码:

index.css

#box {
  width: 1000px;
}

的index.html

<head>
<script src="jquery.js"></script>
</head>
<div id="main">
<div id="box">Box</div>
<link rel="stylesheet" href="index.css">
<script src="index.js"></script>
</div>

index.js

setTimeout(function(){
  console.log($('#box').width())
}, 500)

如果出现以下情况,console.log的输出是什么:

CSS is arrived after 500ms(.i.e server slow): 1000 or other? (I think it should be 1000)
CSS is arrived before 500ms: 1000 or other?

更一般的问题:

Can the applying of external CSS be happened when event loop of JS is not empty?

0 个答案:

没有答案