Color changing text

Size
2,068 Kb
Views
52,624

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 Previews

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!');
Color changing text - Script Codes
Color changing text - Script Codes
Home Page Home
Developer Miro Karilahti
Username miroot
Uploaded July 07, 2022
Rating 3.5
Size 2,068 Kb
Views 52,624
Do you need developer help for Color changing text?

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!

Miro Karilahti (miroot) Script Codes
Create amazing video scripts 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!