Invert custom properties
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 - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Invert custom properties</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="back"> <p class="front">Hello World!</p>
</div>
<button>Switch colors</button> <script src="js/index.js"></script>
</body>
</html>
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'); document.documentElement.style.setProperty('--back', invertColor(back)); document.documentElement.style.setProperty('--front', invertColor(front));
});

Developer | Heydon |
Username | heydon |
Uploaded | December 01, 2022 |
Rating | 3 |
Size | 2,026 Kb |
Views | 4,046 |
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!
Name | Size |
Controlled chaos | 1,562 Kb |
Accessible, pretty radio controls | 2,112 Kb |
Content Aware Navigation | 1,950 Kb |
Focus management of smooth scrolling | 2,506 Kb |
4 columns with padding | 1,576 Kb |
File system with nested lists | 1,640 Kb |
4 columns, no single remainder | 1,563 Kb |
Hash change logging | 2,134 Kb |
Theme color inverter with filter | 0 Kb |
Animated focus styles for kbd users | 1,987 Kb |
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!
Name | Username | Size |
Part 19 Bootstrap split button dropdown | Venkatesha | 1,601 Kb |
Out of the blue | Giaco | 2,537 Kb |
Css3 loader | Clknap | 2,391 Kb |
Zeichensatz | Moklick | 2,058 Kb |
Gradient-ui-button-mark-fx | Tabspace | 1,881 Kb |
Border-radius animation | Yukulele | 2,480 Kb |
Sample Profile Screen | OurDailyBread | 5,375 Kb |
A Pen by aleen42 | Aleen42 | 11,473 Kb |
Slides-07-1 POSITION | Exhtml | 1,909 Kb |
ECharts Version 3.0 - Bar Marker Chart | WebCodePro | 2,726 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!