jquery css添加IE8过滤器

时间:2015-02-13 16:08:56

标签: javascript jquery html css

我尝试使用jquery代码在IE8中制作css3 hack for background-cover

        activeBg.css({ "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + backgroundImage + "',sizingMethod='scale'), progid:DXImageTransform.Microsoft.Alpha(Opacity=30);"})

但它不起作用?为什么呢?

1 个答案:

答案 0 :(得分:0)

好吧,我得到了自己。

一些resone CSS不想内联样式过滤器。 所以我这样做了,它很有效。

    // IE8 HACK
    // Find the background image and regex the uneedet
    var backgroundImage = activeBg.css('backgroundImage').replace(/url\(|\)/gi,"");
    var scale = '"scale"';
    // If this and ie8? if true append an inline stylesheet
    if($("html").hasClass("lt-ie9")) {
        var ie8CoverImg = ".module.car-types-headline .background.active { filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+backgroundImage+", sizingMethod=" + scale + ") progid:DXImageTransform.Microsoft.Alpha(Opacity=30)'; -ms-filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" +backgroundImage+ ", sizingMethod="+scale+") progid:DXImageTransform.Microsoft.Alpha(Opacity=30)'; }";
        $("head style#ie8-cover-fix").remove();
        $("head").append("<style id='ie8-cover-fix'>"+ ie8CoverImg +"</style>");
    }