前言

众所周知,一般有大事情,很多官方网站的首页就会置灰。对这个比较感兴趣,因此就查询了一下,发现设置全站置灰的方式很简单。

记录一下,方便自己查阅。

PS: 本文内容摘抄的,文末有原作者连接

正文

置灰涉及全屏置灰,另外一种是首屏置灰。下面记录一下置灰的代码。

全屏置灰

方式一

亲测,有效。

  1. html {
  2. filter: grayscale(.95);
  3. -webkit-filter: grayscale(.95);
  4. }
复制
方式二

使用svg滤镜,亲测有效。

  1. <svg xmlns="https://www.w3.org/2000/svg">
  2. <filter id="grayscale">
  3.   <feColorMatrix type="matrix" values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"/>
  4.   </filter>
  5. </svg>
  6. <style>
  7.   html {
  8.       filter: url(#grayscale);
  9.   }
  10. </style>
复制

首屏置灰

就是进入是窗口高度置灰,如果拉新滚动后,超过屏幕高度的位置不置灰。

  1. <style>
  2.   html {
  3.       position: relative;
  4.       width: 100%;
  5.       height: 100%;
  6.       overflow: scroll;
  7.       background: #fff;
  8.   }
  9.   html::before {
  10.       content: "";
  11.       position: absolute;
  12.       inset: 0;
  13.       background: rgba(0, 0, 0, 1);
  14.       mix-blend-mode: color;
  15.       pointer-events: none;
  16.       z-index: 10;
  17.   }
  18. </style>
复制

参考文章

  1. 网站置灰的几种方式

相关文章

暂无评论

none
暂无评论...