Transparent Gradient

Developer
Size
2,735 Kb
Views
4,048

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 Previews

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);
}
Transparent Gradient - Script Codes
Transparent Gradient - Script Codes
Home Page Home
Developer Jeff Daze
Username jeffdaze
Uploaded January 18, 2023
Rating 3
Size 2,735 Kb
Views 4,048
Do you need developer help for Transparent Gradient?

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!

Jeff Daze (jeffdaze) Script Codes
Create amazing Facebook ads 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!