在IE浏览器中resize事件执行多次的解决方法
来源:互联网 发布:js判断有没有安装app 编辑:程序博客网 时间:2024/06/05 03:23
最后我找到了一个jquery插件形式的解决方案;
/* =============================================================================== WResize is the jQuery plugin for fixing the IE window resize bug ............................................................................... Copyright 2007 / Andrea Ercolino ------------------------------------------------------------------------------- LICENSE: 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 );
你可以把上面的代码另存为jquery.wresize.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://jquery.com/src/jquery-latest.pack.js"></script> <script type="text/javascript" src="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 testtest test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test 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>
- 在IE浏览器中resize事件执行多次的解决方法
- 在IE浏览器中resize事件执行多次的解决方法
- 解决在IE浏览器中resize事件执行多次
- 解决resize多次执行的问题
- 避免resize多次触发执行的问题
- 修复lte ie8 & chrome 下window 的resize 事件多次执行
- web开发避免resize事件多次执行(更新)
- JQuery给元素绑定click事件多次执行的解决方法
- android中ListView多次刷新重复执行getView的解决方法
- Android中ListView多次刷新重复执行getView的解决方法
- android中ListView多次刷新重复执行getView的解决方法
- 在浏览器中dragdrop和resize对象
- IE chrom浏览器下window.scroll事件触发多次
- table里td标签的width属性在ie浏览器中无效解决方法
- table里td标签的width属性在ie浏览器中无效解决方法
- “IE浏览器不支持在css文件中设定的dialog宽度”解决方法
- 解决checkbox的onclick事件在ie浏览器各版本中不兼容问题
- js中click事件被多次执行
- Sample 3.5:chartype.cpp
- Table假分页
- Printf %输出格式
- Automatic Database Diagnostic Monitor(自动数据库诊断监视器,ADDM)
- 【java】根据身份证,输出年月日
- 在IE浏览器中resize事件执行多次的解决方法
- 文件操作
- 区间dp总结
- apidemo 学习 CreateBitmap DensityActivity ShapeDrawable1 FingerPaint
- C#用Attribute及反射封装sql增删改查
- iphone4 ios7.0.2 降级到6.1.2
- 《一站式学习C编程》学习记录 11月27日
- 素数筛选法
- java学习笔记(四)——io操作