ie9以下及谷歌浏览器等可以用以下代码来实现
<style type="text/css">html{
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%);
filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
}
body{filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);}
</style>
IE9以上比较特殊,需要引入“grayscale.js”才行,同时需要进行浏览器判断
<script type="text/javascript">
window.onload=function(){
var navStr = navigator.userAgent.toLowerCase();
if(navStr.indexOf("msie 10.0")!==-1||navStr.indexOf("rv:11.0")!==-1){ // 判断是IE10或者IE11
grayscale(document.body);
}
}
</script>