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,048 |
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 |
Fukol | 2,461 Kb |
Current Page Test Case | 1,827 Kb |
Vue.js TODO List | 4,218 Kb |
Pixelated Brain Animation | 7,866 Kb |
DIV wormhole | 1,932 Kb |
Content Aware Navigation | 1,950 Kb |
File system with nested lists | 1,640 Kb |
Animated focus styles for kbd users | 1,987 Kb |
Bookish | 2,094 Kb |
Theme color inverter with filter | 0 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 |
A Pen by Sooba | Sooba | 2,516 Kb |
Shape Outside - Polygon | Stacy | 3,954 Kb |
A Pen by Alex Bergin | Abergin | 3,347 Kb |
SlideDown FixedMenu | Mp_graphic | 5,602 Kb |
Loading animation | Hafizfattah | 0 Kb |
Monochrome Form | AlienPiglet | 3,096 Kb |
Cloudy Spiral CSS animation | Hakimel | 6,587 Kb |
404 Page | Saransh | 2,666 Kb |
Classy Blockquote Styling | Andrewwright | 3,212 Kb |
Clock Face Idea | Chrisburnell | 3,196 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!