IE6下 onresize()函数 会死循环 页面会卡死的问题

本文介绍了一种在Internet Explorer浏览器中解决window.onresize事件监听问题的方法。通过使用debounce函数来避免因事件触发过于频繁而导致的问题,实现了对窗口大小变化的有效响应。
   
 /**  resizeWin是你自己要执行的函数。
         * IE下 window.onresize 有bug 可以使用debounce封装监听函数
         * see http://blog.csdn.net/fudesign2008/article/details/7035537
         * @author FuDesign2008@163.com
         * @date   2011-11-30
         * @time   下午04:02:55
         */

        /**
         *
         * @param {Function} callback 回调函数
         * @param {Integer} delay   延迟时间,单位为毫秒(ms),默认150
         * @param {Object} context  上下文,即this关键字指向的对象,默认为null
         * @return {Function}
         */
        function debounce(callback, delay, context) {
            if (typeof(callback) !== "function") {
                return false;
            }
            delay = delay || 150;
            context = context || null;
            var timeout;
            var runIt = function () {
                callback.apply(context);
            };
            return (function () {
                window.clearTimeout(timeout);
                timeout = window.setTimeout(runIt, delay);
            });
        }
        var winResizeHandler = function (event) {
            console.log("window resized");
        };

        window.onresize = debounce(resizeWin, 300);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值