以下js代码用于浮点div。它被称为“浮动ISI”,根据用户滚动的距离而消失。尽管采取了预防措施,但代码在IE 7中不起作用。想知道是否有人可能知道可能存在的问题。
var floating_isi = {
ids: function (staticISI, floatingISI) {
this.staticISI = document.getElementById(staticISI); ;
this.floatingISI = document.getElementById(floatingISI);
this._floatISI();
$(window).scroll(function () {
floating_isi._floatISI();
});
},
_floatISI: function () {
var myHeight = 0; // var for height of browser window
// window.innerWidth does not work in IE8 and below so we check if it gives us a number or not
if (typeof (window.innerWidth) == 'number') {
// it does work so we're not on IE8 or below
myHeight = window.innerHeight;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//IE 6-8 in 'standards compliant mode'
myHeight = document.documentElement.clientHeight;
};
var T = 0; // T = distance between static ISI and top of browser window
T += this.staticISI.offsetTop;
if (window.pageXOffset !== undefined) {
// pageYOffset = how many pixels down has been scrolled from original top of site
T -= pageYOffset;
} else {
//IE8 and below do not have pageXOffset so we use this method
var d = document.documentElement, b = document.body;
T -= (d.scrollTop + b.scrollTop);
}
var difference = (T - myHeight); // distance between static ISI layer and height of browser window
var floatingISIHeight = $(this.floatingISI).height() * -1;
// uncomment for debugging, this renders on the hover ISI layer
//console.log("T = " + T + " myHeight = " + myHeight + " difference = " + difference+" FloatingISIheight= "+floatingISIHeight);
// if the difference between the layers is a certain value, then show/hide layers
if ($(this.staticISI).is(':visible')) {
if (difference <= floatingISIHeight) {
$(this.floatingISI).hide();
} else {
$(this.floatingISI).show();
}
}
}
};