Blogger Information
Blog 4
fans 0
comment 1
visits 8979
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
利用css过滤实现网页夜模式适配
落花微雨的博客
Original
1003 people have browsed it

利用css过滤实现网页暗夜模式适配

关键词:

  1. filter:invert() // 实现网页颜色变化 0=>1 网页由白变黑,1=>0 网页由黑变白。
  2. filter:hue-rotate() // 改变元素颜色,色调旋转 取值范围(0-360deg)

    思路 :通过改变filter:invert()的值来实现网页颜色反转

    代码:

    `<body style="filter: invert(0);">
    <button id="switch">风格切换</button>
    <script>

    1. var btn = document.getElementById('switch');
    2. btn.addEventListener('click', function(){
    3. console.log(document.getElementsByTagName('body')[0].style.filter);
    4. if(document.getElementsByTagName('body')[0].style.filter == 'invert(0)'){
    5. document.getElementsByTagName('body')[0].style.filter = 'invert(1)'
    6. }else{
    7. document.getElementsByTagName('body')[0].style.filter = 'invert(0)'
    8. }
    9. })

    </script>
    </body>`

    css 样式

    html{ background: #fff; } body{ background: #fff; filter: invert(1) hue-rotate(270deg); transform: all 3s ease; }

    这个就很有意思,html,body必须加背景色,不然过滤不会生效

效果预览

filter:invert(0)
filter:invert(1)

有点潦草,不影响使用。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post