您好,欢迎来到华佗养生网。
搜索
您的当前位置:首页ie11 html元素操作,css - 在IE11中过滤html / body元素的灰度[重复] - 堆栈内存溢出

ie11 html元素操作,css - 在IE11中过滤html / body元素的灰度[重复] - 堆栈内存溢出

来源:华佗养生网

由于IE不支持滤镜:grayscale ,您可以尝试使用SVG + JS方法在IE中应用灰度滤镜。

以下是代码片段的一部分。

// Grayscale images only on browsers IE10+ since they removed support for CSS grayscale filter

if (getInternetExplorerVersion() >= 10){

$('img').each(function(){

var el = $(this);

el.css({"position":"absolute"}).wrap("

").clone().addClass('img_grayscale').css({"position":"absolute","z-index":"5","opacity":"0"}).insertBefore(el).queue(function(){

var el = $(this);

el.parent().css({"width":this.width,"height":this.height});

el.dequeue();

});

this.src = grayscaleIE10(this.src);

});

// Quick animation on IE10+

$('img').hover(function () {

$(this).parent().find('img:first').stop().animate({opacity:1}, 200);

},

function () {

$('.img_grayscale').stop().animate({opacity:0}, 200);

}

);

function grayscaleIE10(src){

var canvas = document.createElement('canvas');

var ctx = canvas.getContext('2d');

var imgObj = new Image();

imgObj.src = src;

canvas.width = imgObj.width;

canvas.height = imgObj.height;

ctx.drawImage(imgObj, 0, 0);

var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);

for(var y = 0; y < imgPixels.height; y++){

for(var x = 0; x < imgPixels.width; x++){

var i = (y * 4) * imgPixels.width + x * 4;

var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;

imgPixels.data[i] = avg;

imgPixels.data[i + 1] = avg;

imgPixels.data[i + 2] = avg;

}

}

ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);

return canvas.toDataURL();

};

};

完整示例代码的参考:

IE 11中的输出:

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo7.cn 版权所有 湘ICP备2022005869号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务