newbman Posted February 20, 2006 Share Posted February 20, 2006 I'm trying to make a dynamic menu. When the cursor goes over the <td>, the background color is suppose to change slightly every 10 miliseconds, but there is an error when I try it. Here's the code: <head><style type="text/css">td.mainlinks{ background-color:#0099ff; width: 20%; text-align: center; cursor: pointer;}table{ position:relative; width:100%;}span.main{ font-size:18px; font-family:garamond; color: #000000; font-weight:bold; letter-spacing:2px;}</style><script type="text/javascript">i=1function color(){for (i=1;i<=10;i++){var t=setTimeout("i=i",10)document.getElementById("mytd").style.bgColor="rgb(0,153-10*i,255-10*i)"}}</script></head><body><table border="0"> <td class="mainlinks" id="mytd" onClick='window.location="home.html"' onMouseover="color()"><span class="main">Home</span></td></table></div></body> Nothing happens Link to comment Share on other sites More sharing options...
Webworldx Posted February 28, 2006 Share Posted February 28, 2006 Not really sure what you're looking for with that. Something like: <head><style type="text/css">td.mainlinks { background-color:#0099ff; width: 20%; text-align: center; cursor: pointer;}table { position:relative; width:100%;}span.main { font-size:18px; font-family:garamond; color: #000000; font-weight:bold; letter-spacing:2px;}</style><script type="text/javascript">var num = 1;var tmrColorfunction iDoColor(){ var clrs = "0," + (153 - (10 * num) ) + "," + (255-(10*num)) + ""; document.getElementById("mytd").style.backgroundColor = "rgb(" + clrs + ")" num++;}function iColor(switcher){ if(switcher == 0){ window.clearInterval(tmrColor); num = 1; var clrs = "0," + (153 - (10 * num) ) + "," + (255-(10*num)) + ""; document.getElementById("mytd").style.backgroundColor = "rgb(" + clrs + ")" } else { tmrColor = setInterval( "iDoColor()" , 100) }}</script></head><body><table border="0"><tr><td class="mainlinks" id="mytd" onClick='window.location="home.html"' onMouseover="iColor(1)" onMouseOut="iColor(0)"><span class="main">Home</span></td></tr></table> ?? Link to comment Share on other sites More sharing options...
newbman Posted March 4, 2006 Author Share Posted March 4, 2006 Brilliant! TYVM Link to comment Share on other sites More sharing options...
newbman Posted March 4, 2006 Author Share Posted March 4, 2006 P.S. you are a javascript genius!Also I changed the interval to 10 and instead of subtracting 10*num it subtracts 2*num so it flows more smoothly Link to comment Share on other sites More sharing options...
Webworldx Posted March 4, 2006 Share Posted March 4, 2006 Glad we could help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now