继这个问题之后,我遇到了。我正在尝试应用以下修复以使 getComputedStyle 在用于 jQuery 同位素的代码中与 IE8(和 -)一起使用。但我仍然收到一条错误消息。任何帮助将不胜感激。
我得到 'null' is null 或不是 IE-Tester 的对象错误消息。该网站是http://www.gablabelle.com/
$(document).ready(function(){
var layoutI = 0;
var $container = $("#stream");
var $window = $(window);
//getComputedStyle fix for IE ?
if (!window.getComputedStyle) {
window.getComputedStyle = function(el, pseudo) {
this.el = el;
this.getPropertyValue = function(prop) {
var re = /(\-([a-z]){1})/g;
if (prop == 'float') prop = 'styleFloat';
if (re.test(prop)) {
prop = prop.replace(re, function () {
return arguments[2].toUpperCase();
});
}
return el.currentStyle[prop] ? el.currentStyle[prop] : null;
}
return this;
}
};
function reLayout(){
// getComputedStyle is used here
var mediaQueryId = getComputedStyle( document.body, ':after' ).getPropertyValue('content');
// fix for firefox, remove double quotes
var mediaQueryId = mediaQueryId.replace( /"/g, '' );
// console.log( mediaQueryId );
var windowSize = $window.width();
var masonryOpts;
// update sizing options
switch ( mediaQueryId ) {
case 'bigger' :
masonryOpts = {
columnWidth: 270,
gutterWidth: 30
};
break;
case 'big' :
masonryOpts = {
columnWidth: 220,
gutterWidth: 20
};
break;
case 'medium' :
masonryOpts = {
columnWidth: 166,
gutterWidth: 20
};
break;
case 'small' :
masonryOpts = {
columnWidth: $container.width() / 2,
gutterWidth: 0
};
break;
};
$container.isotope({
resizable: false, // disable resizing by default, we'll trigger it manually
itemSelector : "article.post",
animationEngine: "best-available",
masonry: masonryOpts,
onLayout: function() {
// console.log('layout!' + (layoutI++) )
forceLoad();
setTimeout(function(){
html_height = $container.height();
$("#sidebar").height(html_height - masonryOpts.gutterWidth);
}, 500);
}
});
};
// start up isotope with default settings
$container.imagesLoaded( function(){
reLayout();
$window.smartresize( reLayout );
});