Transparent Gradient
How do I make an transparent gradient?
An implementation of a transparent gradient using solid color backgrounds. What is a transparent gradient? How do you make a transparent gradient? This script and codes were developed by Jeff Daze on 18 January 2023, Wednesday.
Transparent Gradient - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Transparent Gradient</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="bgDemo"></div>
<button id="color1"></button>
<button id="color2"></button>
<button id="color3"></button>
<button id="color4"></button>
<button id="color5"></button>
<p>Click the buttons above to change the color of the gradient.</p> <script src="js/index.js"></script>
</body>
</html>
Transparent Gradient - Script Codes CSS Codes
/* default gradient here */
.bgDemo{ margin:10px auto 10px; border:1px solid #003; height:200px; box-shadow: 0 0 10px 5px #999; /* GS styles for gradients here */ /* use a solid color as the base */ /* background-color: #333; */ /* then create a greyscale gradient to overlay */ filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr='#cccccc', endColorstr='#333333'); background: #333; /* IE specific fallback */ /* create layered background stacks to create the gradient, the last value is a solid hex color */ background: -moz-linear-gradient(top, rgba(255,255,255,.5) 0%, rgba(255,255,255,0.1) 100%), #333; /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0.5)), color-stop(100%,rgba(255,255,255,0.1))), #333; /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0.1) 100%), #333; /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0.1) 100%), #333; /* Opera 11.10+ */ background: -ms-linear-gradient(top, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0.1) 100%), #333; /* IE10+ */ background: linear-gradient(to bottom, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0.1) 100%), #333; /* W3C */
}
/* button styles */
button{ width:20px; height:20px;
}
#color1{ background: #333;
}
#color2{ background: #3DBC7C;
}
#color3{ background: #FBAA1C;
}
#color4{ background: #EF3E36;
}
#color5{ background: #4E35EF;
}
Transparent Gradient - Script Codes JS Codes
//bind clicks to buttons...
$("#color1").addEventListener('click', function() { setColor("333");
}, false);
$("#color2").addEventListener('click', function() { setColor("3DBC7C");
}, false);
$("#color3").addEventListener('click', function() { setColor("FBAA1C");
}, false);
$("#color4").addEventListener('click', function() { setColor("EF3E36");
}, false);
$("#color5").addEventListener('click', function() { setColor("4E35EF");
}, false);
//function to set the color for the gradient example
//accepts a DOM element with a color set for the background
function setColor(hex){ //build the CSS definition... var bgCss = "background: #"+hex+"; \ background: -moz-linear-gradient(top, rgba(255,255,255,.5) 0%, rgba(255,255,255,0.1) 100%), #"+hex+"; \ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0.5)), color-stop(100%,rgba(255,255,255,0.1))), #"+hex+"; \ background: -webkit-linear-gradient(top, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0.1) 100%), #"+hex+"; \ background: -o-linear-gradient(top, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0.1) 100%), #"+hex+"; \ background: -ms-linear-gradient(top, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0.1) 100%), #"+hex+"; \ background: linear-gradient(to bottom, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0.1) 100%), #"+hex+";"; //now append the class to the document to apply the new color... var style = document.createElement("style"); style.type = "text/css"; style.innerHTML = ".bgDemo { "+bgCss+" }"; document.getElementsByTagName('head')[0].appendChild(style);
}
//utility functions...
//TAKE THAT jQuery!!
function $(selector){ return document.querySelector(selector);
}
Developer | Jeff Daze |
Username | jeffdaze |
Uploaded | January 18, 2023 |
Rating | 3 |
Size | 2,735 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 |
Simulation of famous C64 code... | 1,788 Kb |
Desktop Notifications | 1,975 Kb |
Code snippets for a Puyo clone | 2,363 Kb |
JS test and Box Shadow | 1,906 Kb |
Winter Scene | 2,739 Kb |
A test card for a Munchkin-like game | 2,044 Kb |
Quick torus demo three.js | 1,894 Kb |
Starfield using KineticJS | 3,290 Kb |
Tilemap Edge CSS | 2,159 Kb |
Circular Drag and Drop | 2,451 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 |
Amazing CSS Menu with Notification Badges | Faizanasad | 2,549 Kb |
A Pen by Mohomed Anees | Mohomedanees | 12,597 Kb |
Resize image | Happyhj | 1,892 Kb |
Importable Clearfix | Corysimmons | 1,411 Kb |
Pagepilling.js | Blossk | 6,554 Kb |
Twitch TV | Natester13 | 4,488 Kb |
A Pen by John Malc | F789gh | 1,420 Kb |
Whyutils | LeYvan | 3,752 Kb |
Mini Profile | Frytyler | 3,828 Kb |
A form arranged using automatic placement. | Vikasford | 2,103 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!