【发布时间】:2011-09-02 01:01:21
【问题描述】:
脚本推理: 根据浏览器检测到的宽度和高度重新加载各种 CSS 脚本。当浏览器正在调整大小时,需要重新加载窗口以重新加载其他 JavaScript。
出现的问题: IE喜欢不断循环。
与其他脚本的兼容性: Chrome、FireFox、Safari 工作
使用的脚本:
<body onResize="window.location.href = window.location.href;">
请有人提出更好的解决方案或建议!这必须适用于 Safari、IE 和 FireFox。
如果逻辑基于什么类型的浏览器,可能还有其他情况?
以下解决方案(JQUERY):window.resize event firing in Internet Explorer
$(document).ready(function(){
var winWidth = $(window).width(),
winHeight = $(window).height();
$(window).resize(function(){
onResize = function() {
//The method which sets the LEFT css property which triggers
//window.resize again and it was a infinite loop
setWrapperPosition($mainWrapper.parent());
}
//New height and width
var winNewWidth = $(window).width(),
winNewHeight = $(window).height();
// compare the new height and width with old one
if(winWidth!=winNewWidth || winHeight!=winNewHeight)
{
window.clearTimeout(resizeTimeout);
resizeTimeout = window.setTimeout(onResize, 10);
}
//Update the width and height
winWidth = winNewWidth;
winHeight = winNewHeight;
});
});
【问题讨论】:
-
缺陷是根据页面大小加载css的设计。
-
Google 搜索“CSS 媒体查询”...
-
作为替代方案,您可以人为地拆分 CSS 并在大小更改处理程序中的
<body>或<html>上设置一个类。
标签: javascript ajax internet-explorer cross-browser