Color changing text
How do I make an color changing text?
Letters change color when mouse is over them.. What is a color changing text? How do you make a color changing text? This script and codes were developed by Miro Karilahti on 07 July 2022, Thursday.
Color changing text - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Color changing text</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!--Color changing happens by changing classes--> <script src="js/index.js"></script>
</body>
</html>
Color changing text - Script Codes CSS Codes
body{ background: #356; padding: 100px 0; font-family: Arial,sans-serif; font-size: 500%; text-align: center; text-shadow: 0 1px 3px rgba(0,0,0,.4); cursor: default;
}
Color changing text - Script Codes JS Codes
//Colors to use in text
var colors = new Array('#3498db', '#e74c3c', '#2ecc71', '#e67e22', '#1abc9c', '#f1c40f');
//Function that prints required classes
function printCSS(){ document.write('<style>'); for(i = 0; i < colors.length; i++){ document.write('.color-' + i + '{color:' + colors[i] + '}'); } document.write('</style>');
}
//Function that generates the text
function generateText(text){ for(i = 0; i < text.length; i++){ var rnd = Math.floor(Math.random() * colors.length); document.write('<span id="letter-' + i + '" class="color-' + rnd + '" onmouseover="changeColor(this.id)">'); document.write(text[i]); document.write('</span>'); }
}
//Function that changes color of letter
function changeColor(el){ el = document.getElementById(el); var rnd = Math.floor(Math.random() * colors.length); while(el.className == 'color-' + rnd){ rnd = Math.floor(Math.random() * colors.length); } el.className = 'color-' + rnd;
}
printCSS();
generateText('Wow, these letters change color!');
Developer | Miro Karilahti |
Username | miroot |
Uploaded | July 07, 2022 |
Rating | 3.5 |
Size | 2,068 Kb |
Views | 52,624 |
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 |
Pure CSS Card Deck | 3,245 Kb |
Long Shadow Calendar Icon | 1,856 Kb |
Pure CSS Gallery | 3,817 Kb |
Social Icons | 2,941 Kb |
Expanding Photo Stack | 2,083 Kb |
Long Shadow Camera Icon | 1,825 Kb |
Calendar | 2,033 Kb |
Background change in pure CSS | 3,236 Kb |
Corner Ribbons | 1,911 Kb |
Single element Nexus 5 | 2,159 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 |
Sidebar Thing | Jonambas | 2,779 Kb |
WRENCH - STAFF | Lolita-adams | 1,608 Kb |
Haml Calendar | Katydecorah | 5,643 Kb |
Break Out | AzazelN28 | 12,431 Kb |
Ball Physics | Getsetbro | 3,149 Kb |
Slider for stackoverflow | KKOKU | 3,222 Kb |
CSS Link Icons with jQuery Titles | Nicwinn | 2,312 Kb |
CSS Heart Loaders | Nourabusoud | 2,161 Kb |
Expert Help | SinceSidSlid | 4,064 Kb |
Banner Ad | Raquellorenzana | 4,172 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!