Invert custom properties

2,026 Kb

How do I make an invert custom properties?

What is a invert custom properties? How do you make a invert custom properties? This script and codes were developed by Heydon on 01 December 2022, Thursday.

Invert custom properties Previews

Invert custom properties - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Invert custom properties</title> <link rel="stylesheet" href="css/style.css">
<body> <div class="back"> <p class="front">Hello World!</p>
<button>Switch colors</button> <script src="js/index.js"></script>

Invert custom properties - Script Codes CSS Codes

:root { --back: #eee; --front: #111;
body { background-color: var(--back);
div { background-color: var(--back); color: var(--front); padding: 1rem; margin-bottom: 1em;

Invert custom properties - Script Codes JS Codes

function invertColor(hex) { hex = hex.trim(); hex = hex.slice(1); if (hex.length === 3) { hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; } if (hex.length !== 6) { throw new Error('Invalid HEX color.'); } var r = (255 - parseInt(hex.slice(0, 2), 16)).toString(16), g = (255 - parseInt(hex.slice(2, 4), 16)).toString(16), b = (255 - parseInt(hex.slice(4, 6), 16)).toString(16); return '#' + padZero(r) + padZero(g) + padZero(b);
function padZero(str, len) { len = len || 2; var zeros = new Array(len).join('0'); return (zeros + str).slice(-len);
document.querySelector('button').addEventListener('click', function () { var rootStyles = window.getComputedStyle(document.documentElement); var back = rootStyles.getPropertyValue('--back'); var front = rootStyles.getPropertyValue('--front');'--back', invertColor(back));'--front', invertColor(front));
Invert custom properties - Script Codes
Invert custom properties - Script Codes
Home Page Home
Developer Heydon
Username heydon
Uploaded December 01, 2022
Rating 3
Size 2,026 Kb
Views 4,048
Do you need developer help for Invert custom properties?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Heydon (heydon) Script Codes
Create amazing captions with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!