---
title: "IE下WINRESIZE 卡死解决方法"
author: "zimo888"
date: "2012-04-24T17:56:54Z"
tags: []
categories: ["Web前端"]
slug: "ie-winresize"
draft: false
lastmod: "2012-04-24T17:56:54Z"
id: 1497058
url: "https://zimo888.iteye.com/blog/1497058"
---

IE调用winresize事件会假死，寻遍网络，最后在国外网站找到答案，靠谱。
var resizeEventTimer= null;

$(window).resize(function(){

    //IE fires multiple events hence we don't want to delay all of them but only the last one. Hence Clear if exists
    if (resizeEventTimer){
	clearTimeout(resizeEventTimer);
    }

    // Set Timeout and delay for 100 ms (should be enough - increase if problem persists)
    resizeEventTimer = setTimeout(function(){

	// start-mycode
	var marginTop = ($(window).height() - settings.dHeight) / 3;
	var marginLeft = ($(window).width() - settings.dWidth) / 2;
	$('#myDiv').css({
	    top: marginTop + 'px',
	    left:  marginLeft + 'px'
	});
	// end-mycode

    }, 100);

});