网页设置灰色与还原

1.设置网页为灰色

//创建一个元素
var globalCss = document.createElement("style");
//设置这个元素的类型 <style type = "text/css"></style>
globalCss.type = "text/css";
//获取head标签,并把<style type = "text/css"></style>添加进去
document.getElementsByTagName("head")[0].append(globalCss)
//设置style标签的样式
globalCss.appendChild(document.createTextNode("html{-webkit-filter: grayscale(100%) !important; -moz-filter: grayscale(100%) !important;-ms-filter: grayscale(100%) !important;-o-filter: grayscale(100%) !important;filter: grayscale(100%) !important;filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1) !important;}"));

2.还原网页颜色

//创建一个元素
var globalCss = document.createElement("style");
//设置这个元素的类型 <style type = "text/css"></style>
globalCss.type = "text/css";
//获取head标签,并把<style type = "text/css"></style>添加进去
document.getElementsByTagName("head")[0].append(globalCss)
//设置style标签的样式
globalCss.appendChild(document.createTextNode("html{-webkit-filter:none !important;}"));
注:做的时候可以封装成一个方法,传入对应的参数进行调用即可。
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容