Introduction:
Here I will explain how to generate random colors for div using JavaScript and change color of div at regular intervals of time using JavaScript in asp.net.
Description:
In previous articles I explained jQuery Change background color of div, jQuery fadein fadeout effect,jQuery get current page url and title, jQuery create rounded corners for textbox and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to generate random colors for div using JavaScriptin asp.net.
In previous articles I explained jQuery Change background color of div, jQuery fadein fadeout effect,jQuery get current page url and title, jQuery create rounded corners for textbox and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to generate random colors for div using JavaScriptin asp.net.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Generate Random Colors using javascript</title>
<script type="text/javascript">
// Run function for every second of timer
setInterval(rgbcolors, 1000);
function rgbcolors() {
// rgb string generation
var col = "rgb("
+ Math.floor(Math.random() * 255) + ","
+ Math.floor(Math.random() * 255) + ","
+ Math.floor(Math.random() * 255) + ")";
//change the text color with the new random color
document.getElementById("divstyle").style.color = col;
}
</script>
</head>s
<body>
<form id="form1" runat="server" >
<div id="divstyle" style="font:bold 24px verdana">Aspdotnet-suresh.com</div>
</form>
</body>
</html>
|
Live Demo
|
No comments:
Post a Comment