IE6浏览器下resize事件被执行了多次解决方法


Posted in Javascript onDecember 11, 2012

在IE浏览器下,一次resize事件被执行了多次。这是IE6和IE7的一个比较广为认知的问题,这个问题在这两个版本的浏览器中表现有所不同,通常IE6下会比IE7下更为糟糕。
现在已经有了一个较好的解决方案,让jquery.wresize.js这个jquery插件来帮你:
Js代码

/* 
=============================================================================== 
WResize is the jQuery plugin for fixing the IE window resize bug 
............................................................................... 
Copyright 2007 / Andrea Ercolino 
------------------------------------------------------------------------------- 
LICENSE: php">http://www.opensource.org/licenses/mit-license.php 
WEBSITE: http://noteslog.com/ 
=============================================================================== 
*/ 
( function( $ ) 
{ 
$.fn.wresize = function( f ) 
{ 
version = '1.1'; 
wresize = {fired: false, width: 0}; 
function resizeOnce() 
{ 
if ( $.browser.msie ) 
{ 
if ( ! wresize.fired ) 
{ 
wresize.fired = true; 
} 
else 
{ 
var version = parseInt( $.browser.version, 10 ); 
wresize.fired = false; 
if ( version < 7 ) 
{ 
return false; 
} 
else if ( version == 7 ) 
{ 
//a vertical resize is fired once, an horizontal resize twice 
var width = $( window ).width(); 
if ( width != wresize.width ) 
{ 
wresize.width = width; 
return false; 
} 
} 
} 
} 
return true; 
} 
function handleWResize( e ) 
{ 
if ( resizeOnce() ) 
{ 
return f.apply(this, [e]); 
} 
} 
this.each( function() 
{ 
if ( this == window ) 
{ 
$( this ).resize( handleWResize ); 
} 
else 
{ 
$( this ).resize( f ); 
} 
} ); 
return this; 
}; 
} ) ( jQuery );

如何使用,请看这个例子test page
Js代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow:hidden;"> 
<head> 
<title> test window resize </title> 
<script type="text/javascript" src=http://www.hake.cc/kf/201109/"http://jquery.com/src/jquery-latest.pack.js"></script> 
<script type="text/javascript" src=http://www.hake.cc/kf/201109/"jquery.wresize.js"></script> 
<script type="text/javascript"> 
jQuery( function( $ ) 
{ 
function content_resize() 
{ 
var w = $( window ); 
var H = w.height(); 
var W = w.width(); 
$( '#content' ).css( {width: W-20, height: H-20} ); 
} 
$( window ).wresize( content_resize ); 
content_resize(); 
} ); 
</script> 
</head> 
<body> 
<div id="content" style="border: 1px dashed silver; position:absolute; overflow:auto;"> 
test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test 
</div> 
</body> 
</html>
Javascript 相关文章推荐
LBS blog sql注射漏洞[All version]-官方已有补丁
Aug 26 Javascript
jquery bind(click)传参让列表中每行绑定一个事件
Aug 06 Javascript
使用JS获取当前地理位置方法汇总
Dec 18 Javascript
基于js实现微信发送好友如何分享到朋友圈、微博
Nov 30 Javascript
Javascript实现Array和String互转换的方法
Dec 21 Javascript
BootStrap Typeahead自动补全插件实例代码
Aug 10 Javascript
JavaScript BASE64算法实现(完美解决中文乱码)
Jan 10 Javascript
Ext JS 实现建议词模糊动态搜索功能
May 13 Javascript
vue实现仿淘宝结账页面实例代码
Nov 08 Javascript
Electron-vue开发的客户端支付收款工具的实现
May 24 Javascript
通过微信公众平台获取公众号文章的方法示例
Dec 25 Javascript
package.json中homepage属性的作用详解
Mar 11 Javascript
什么是json和jsonp,jQuery json实例详详细说明
Dec 11 #Javascript
JavaScript子窗口ModalDialog中操作父窗口对像
Dec 11 #Javascript
javascript中window.event事件用法详解
Dec 11 #Javascript
js 延迟加载 改变JS的位置加快网页加载速度
Dec 11 #Javascript
js控制CSS样式属性语法对照表
Dec 11 #Javascript
javascript向flash swf文件传递参数值注意细节
Dec 11 #Javascript
ajax的hide隐藏问题解决方法
Dec 11 #Javascript
You might like
优化使用mysql存储session的php代码
2008/01/10 PHP
PHP数据类型之布尔型的介绍
2013/04/28 PHP
yii2.0整合阿里云oss上传单个文件的示例
2017/09/19 PHP
PHP二维数组实现去除重复项的方法【保留各个键值】
2017/12/21 PHP
ajaxControlToolkit AutoCompleteExtender的用法
2008/10/30 Javascript
Javascript 遍历对象中的子对象
2009/07/03 Javascript
动态加载jquery库的方法
2014/02/12 Javascript
javascript框架设计读书笔记之字符串的扩展和修复
2014/12/02 Javascript
jQuery实现MSN中文网滑动Tab菜单效果代码
2015/09/09 Javascript
原生JavaScript制作计算器
2016/10/16 Javascript
使用Bootstrap Tabs选项卡Ajax加载数据实现
2016/12/23 Javascript
jQuery插件开发发送短信倒计时功能代码
2017/05/09 jQuery
Bootstrap treeview实现动态加载数据并添加快捷搜索功能
2018/01/07 Javascript
JS 实现微信扫一扫功能
2018/09/14 Javascript
对angularjs框架下controller间的传值方法详解
2018/10/08 Javascript
微信小程序实现的日期午别医生排班表功能示例
2019/01/09 Javascript
Node.js使用supervisor进行开发中调试的方法
2019/03/26 Javascript
微信小程序实现滑动翻页效果(完整代码)
2019/12/06 Javascript
[01:28:43]2014 DOTA2华西杯精英邀请赛5 24 DK VS CIS
2014/05/25 DOTA
pandas数据处理基础之筛选指定行或者指定列的数据
2018/05/03 Python
python爬虫的数据库连接问题【推荐】
2018/06/25 Python
django实现web接口 python3模拟Post请求方式
2019/11/19 Python
python和c语言哪个更适合初学者
2020/06/22 Python
Python 如何创建一个线程池
2020/07/28 Python
Python关于拓扑排序知识点讲解
2021/01/04 Python
美国折衷生活方式品牌:Robert Graham
2018/07/13 全球购物
ANINE BING官方网站:奢华的衣橱基本款和时尚永恒的单品
2019/11/26 全球购物
一个SQL面试题
2014/08/21 面试题
专业毕业生个性的自我评价
2013/10/03 职场文书
桥梁工程专业求职信
2014/04/21 职场文书
代理协议书
2014/04/22 职场文书
销售员自我评价
2015/03/11 职场文书
2015初中政教处工作总结
2015/07/21 职场文书
公司仓库管理制度
2015/08/04 职场文书
HTML5来实现本地文件读取和写入的实现方法
2021/05/25 HTML / CSS
win10更新失败无限重启解决方法
2022/04/19 数码科技