Use JavaScript to add night mode _javascript tips for Web pages

Source: Internet
Author: User

HTML+CSS:

Copy Code code as follows:

<div class= "Cover" ></div>

Copy Code code as follows:

<style>
. cover{
position:fixed;
top:0px;
left:0px;
outline:5000px solid Rgba (0, 0, 0, 0.3);
z-index:99999;
}
</style>

Then write a nightly pattern plus in javascript:

Copy Code code as follows:

<script>
var brightness;
Show Matte
function cover (brightness) {
if (typeof (div) = = ' undefined ') {
div = document.createelement (' div ');
Div.setattribute (' style ', ' position:fixed;top:0;left:0;outline:5000px solid;z-index:99999; ');
Document.body.appendChild (DIV);
} else {
Div.style.display = ';
}
Div.style.outlineColor = ' Rgba (0,0,0, ' + brightness + ') ';
}
Event Monitoring
Window.addeventlistener (' KeyDown ', function (e) {
if (e.altkey && E.keycode = =) {//alt+z: Open night Mode
Cover (brightness = 0.3);
}
if (e.altkey && e.keycode =) {//alt+x: Off
Cover (brightness = 0);
}
if (e.altkey && E.keycode = =) {//alt+↑: Increase brightness
if (brightness-0.05 > 0.05) cover (brightness-= 0.05);
}
if (e.altkey && E.keycode = =) {//alt+↓: Lower brightness
if (brightness + 0.05 < 0.95) Cover (brightness = 0.05);
}
}, False);
</script>

Can also be written as a Greasemonkey script, extended as a browser to any page to increase the night mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.