浏览器窗口变化了1像素时就触发resize事件,然后随着变化不断重复触发。应该注意不要在这个事件的处理程序中加入大计算量的代码,因为这些代码有可能被频繁执行,从而导致浏览器反映明显变慢。
如果必须加则让resize事件按指定频率执行。避免不断执行。
-----------------------------------例子----------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<title>resize 频率</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
<style type="text/css">
body
{
margin: 0px;
padding: 0px;
display:-moz-box;
display:-webkit-box;
display:box;
-moz-box-orient:vertical;
-webkit-box-orient:vertical;
box-orient:vertical;
width: 100%;
overflow: hidden;
}
body>header
{
height:200px;
background-color: #338822;
}
body>footer
{
height:100px;
background-color: #338822;
}
body>div
{
-moz-box-flex:1;
-webkit-box-flex:1;
box-flex:1;
background-color: #778822;
}
</style>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded",function(event){
window.resizeWait = false;
window.resizeInterval = 500;
var setfullScreen=function(){
document.body.style.height=document.documentElement.clientHeight+"px";
}
var resize = function resize(event){
if(!window.resizeWait){
window.resizeWait = true;
setTimeout(function(){
setfullScreen();
window.resizeWait = false;
},1000);
}
};
window.addEventListener("resize",resize,false);
setfullScreen();
},false);
</script>
</head>
<body>
<header>标题</header>
<div>
<article>
<h1>svg实现</h1>
<section>
<nav>标题</nav>
</section>
</article>
<article>
<h1>css实现</h1>
</article>
<article>
<h1>canvas实现</h1>
</article>
</div>
<footer>COPYRIGHT@张森</footer>
</body>
</html>