Javascript 冻结IE的代码

Javascript 冻结IE的代码,javascript,jquery,facebook,internet-explorer-8,Javascript,Jquery,Facebook,Internet Explorer 8,我有一个facebook tab应用程序,可以一页一页地改变高度,所以我写了一个“快照”代码 将页脚的位置更改为绝对或静态,但每当我使用IE8访问页面时,都会冻结IExplorer 起初,我认为$(document).height()会使页面冻结,但表面上看起来不是这样。因此,任何建议都将不胜感激 var height = $(this).height(), width = $(this).width(); $( window ).resize(function() { fs

我有一个facebook tab应用程序,可以一页一页地改变高度,所以我写了一个“快照”代码 将页脚的位置更改为绝对或静态,但每当我使用IE8访问页面时,都会冻结IExplorer

起初,我认为$(document).height()会使页面冻结,但表面上看起来不是这样。因此,任何建议都将不胜感激

var height = $(this).height(),
    width  = $(this).width();

$( window ).resize(function() {
    fsnap();
});

$(document).bind('DOMSubtreeModified', function() {
    if($(this).height() != height || $(this).width() != width) {
        fsnap();
    }
});


function getDocHeight() {
var D = document;
return Math.max(
    D.body.scrollHeight, D.documentElement.scrollHeight,
    D.body.offsetHeight, D.documentElement.offsetHeight,
    D.body.clientHeight, D.documentElement.clientHeight
);
}

function fsnap(){
var dH;
if (navigator.appName != 'Microsoft Internet Explorer') {
    dH = $(document).height();
}else{
    dH = getDocHeight();
}

if(dH>$(".main").height()) $(".footer").addClass("footersnap");
else $(".footer").removeClass("footersnap");

if(dH > $(".footer").offset().top + $(".footer").height())
    $(".footer").removeClass("footersnap");
}

可能是完全缺乏对突变事件的支持,而事实上它们现在已经被正式弃用,甚至没有得到真正的支持?你可能是对的,但我想突变部分正在工作,因为每当我删除fsnap函数内部时,它不会冻结IE,但我认为fsnap代码有问题,当然不太确定。在js文件的开头,var height=$(this.height(),width=$(this.width();去编辑我以前的评论,不小心删除了它。看起来addClass()/removeClass()正在触发DOMSubtreeModified。由于您正在对照屏幕的原始高度检查当前高度,因此会进入一个无限循环,调用fsnap并触发DOMSubtreeModified。噢,谢谢你,Nathan,这是正确的。我想我应该检查一下浏览器中是否有修改过的部分。谢谢