css to turn web pages into black and white

王林
Release: 2020-05-12 09:19:22
forward
4423 people have browsed it

css to turn web pages into black and white

There are three ways to globally change the color of the entire web page, namely: direct css setting, adding svg filter, and changing the color by traversing all tags through js.

1. Set css directly

Edit the style directly, and then set class

.gray { -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filter: grayscale(100%); filter: grayscale(100%); filter: gray; }
Copy after login

where it needs to be applied (video tutorial:css video tutorial)

2. svg

Write the svg file first

    
Copy after login

css call

filter: url(gray.svg#grayscale);
Copy after login

3.js traversal

Just insert the code directly La, it is impossible to write it by hand (ps: rgba and !important cannot be changed, others have not been tested)

Copy after login

The js source is not very good, which will cause the webpage to load too slowly. You can download it manually. Local grayscale.js (after clicking F12, switch to the Network tab, refresh the web page and a file will appear, right-click save as)

Then use js or jq to call

/*js调用*/ grayscale(document.getElementById("thisImage")); /*jq调用*/ grayscale($("#thisImage"));
Copy after login

Recommended tutorial:cssquickstart

The above is the detailed content of css to turn web pages into black and white. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!