CSS
.site-gray, .site-gray *{
filter: gray !important;
filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
}
HTML及JS
<a href="javascript:;" class="site-gray" data-gray="0">网站变灰</a>
<script src="grayscale.js"></script>
<script>
var navStr = navigator.userAgent.toLowerCase();
$(".site-gray").click(function(){
var gray = $(this).attr("data-gray");
if( gray == 0 )
{
if(navStr.indexOf("msie 10.0")!==-1||navStr.indexOf("rv:11.0")!==-1){
grayscale(document.body);
grayscale(document.getElementsByTagName("img"));
}
$("html").addClass("site-gray");
$(this).attr("data-gray", 1);
}
else
{
if(navStr.indexOf("msie 10.0")!==-1||navStr.indexOf("rv:11.0")!==-1){
grayscale.reset(document.body);
grayscale.reset(document.getElementsByTagName("img"));
}
$("html").removeClass("site-gray");
$(this).attr("data-gray", 0);
}
});
</script>
相关文件
grayscale.js