关于window的resize事件
2024-10-10 20:39:04
也许你也遇到过这样的问题,或者还没注意到有过这样的问题,如下代码,在窗口发生变化时,会进入死循环:
var _funResize = function(){
console.log('resize...' + Math.random());
}
$(window).bind('resize',_funResize);
是问题,总得研究解决,方案:
var _funResize = function(){
// 先解除绑定
$(window).unbind('resize',_funResize); console.log('resize...' + Math.random()); // 重新绑定
setTimeout(function(){
$(window).bind('resize',_funResize);
},);
}
$(window).bind('resize',_funResize);
但是这种方法只能是触发第一次resize事件,有时我们是想触发最后一次resize事件。可以通过时间来判断
var rtime = new Date();
var timeout = false;
var delta = ;
$(window).resize(function() {
rtime = new Date();
if (timeout === false) {
timeout = true;
setTimeout(resizeend, delta);
}
}); function resizeend() {
if (new Date() - rtime < delta) {
setTimeout(resizeend, delta);
} else {
timeout = false;
alert($(window).height());
}
}
最新文章
- innobackupex 重启MySQL
- 50.ISE布局布线错误
- 关于insertBefore
- LSJ_NHibernate第一章 NHibernate介绍
- asp.net:验证控件中ValidationExpression的写法
- linux系统下安装apache与tomcat
- ECSHOP商城全站自定义TITLE标题设置
- cocos2d-x3.2中map的基本操作和使用
- if(){}else 语句的正确写法以及它的嵌套使用
- python爬去电影天堂恐怖片+游戏
- 3DES加密
- [USACO08JAN]跑步Running
- Ubuntu全盘备份与恢复,亲自总结,实测可靠
- 常见六大Web安全攻防解析
- FTP:mget匹配文件名后下载
- ansible 剧本
- ThinkPHP5.0 实现 app微信支付功能
- Structured Streaming教程(2) —— 常用输入与输出
- webstocket 聊天
- mybatis批量更新update-设置多个字段值 报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near