»
EnglishFrenchVietnamese

Print - Tag Fader script - JavaScriptBank.com

Full version: jsB@nk » Utility » Tag Fader script
URL: https://www.javascriptbank.com/tag-fader-script.html

Tag Fader script © JavaScriptBank.comThis JavaScript demonstrates several techniques for fading the background of selected HTML components such as buttons, textboxes, and page backgrounds, from one color to another.

Full version: jsB@nk » Utility » Tag Fader script
URL: https://www.javascriptbank.com/tag-fader-script.html



JavaScript
<script type="text/javascript"><!-- Begin/* comp = name (ID="comp") of the HTML page component to fadecbeg = start value for color in #rrggbb formatcend = end value for color in #rrggbb formatiter = number of steps in the fade from start color to end colortime = number of milliseconds to display each steprbeg = start value for red component of rbg colorgbeg = start value for green component of rbg colorbbeg = start value for blue component of rbg colorrend = end value for red component of rbg colorgend = end value for green component of rbg colorbend = end value for blue component of rbg color */var hstr = '#';var hdig = "0123456789abcdef";function mOvr(comp, cbeg, cend, iter, time) {  var rbeg = hdig.indexOf(cbeg.substr(1,1))*16 + hdig.indexOf(cbeg.substr(2,1));  var gbeg = hdig.indexOf(cbeg.substr(3,1))*16 + hdig.indexOf(cbeg.substr(4,1));  var bbeg = hdig.indexOf(cbeg.substr(5,1))*16 + hdig.indexOf(cbeg.substr(6,1));  var rend = hdig.indexOf(cend.substr(1,1))*16 + hdig.indexOf(cend.substr(2,1));  var gend = hdig.indexOf(cend.substr(3,1))*16 + hdig.indexOf(cend.substr(4,1));  var bend = hdig.indexOf(cend.substr(5,1))*16 + hdig.indexOf(cend.substr(6,1));  for ( i = 1, r = rbeg, g = gbeg, b = bbeg;    i <= iter;    r = Math.round(rbeg + i * ((rend - rbeg) / (iter-1))),    g = Math.round(gbeg + i * ((gend - gbeg) / (iter-1))),    b = Math.round(bbeg + i * ((bend - bbeg) / (iter-1))), i++ ) {    hstr = '#' + hdig.charAt(Math.floor(r/16)) + hdig.charAt(r%16) +      hdig.charAt(Math.floor(g/16)) + hdig.charAt(g%16) +      hdig.charAt(Math.floor(b/16)) + hdig.charAt(b%16);    setTimeout('var el = document.getElementById("' + comp + '"); el.style.backgroundColor = "' + hstr + '";', i * time);  }}function mOut(comp, cbeg, cend, iter, time) {  var rbeg = hdig.indexOf(cbeg.substr(1,1))*16 + hdig.indexOf(cbeg.substr(2,1));  var gbeg = hdig.indexOf(cbeg.substr(3,1))*16 + hdig.indexOf(cbeg.substr(4,1));  var bbeg = hdig.indexOf(cbeg.substr(5,1))*16 + hdig.indexOf(cbeg.substr(6,1));  var rend = hdig.indexOf(cend.substr(1,1))*16 + hdig.indexOf(cend.substr(2,1));  var gend = hdig.indexOf(cend.substr(3,1))*16 + hdig.indexOf(cend.substr(4,1));  var bend = hdig.indexOf(cend.substr(5,1))*16 + hdig.indexOf(cend.substr(6,1));  for ( i = 1, r = rend, g = gend, b = bend;    i <= iter;    r = Math.round(rend - i * ((rend - rbeg) / (iter-1))),    g = Math.round(gend - i * ((gend - gbeg) / (iter-1))),    b = Math.round(bend - i * ((bend - bbeg) / (iter-1))), i++ ) {    hstr = '#' + hdig.charAt(Math.floor(r/16)) + hdig.charAt(r%16) +      hdig.charAt(Math.floor(g/16)) + hdig.charAt(g%16) +      hdig.charAt(Math.floor(b/16)) + hdig.charAt(b%16);    setTimeout('var el = document.getElementById("' + comp + '"); el.style.backgroundColor = "' + hstr + '";', i * time);  }}// End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form id="myForm" name="myForm" style="border: 3px dashed blue; width: 250px"><div align="center"><br><input type=button id="button1" style="background: #cc9933"  value="Fade this button"  onMouseOver="mOvr('button1','#cc9933','#6699cc',10,100)"  onMouseOut="mOut('button1','#cc9933','#6699cc',10,100)"  onMouseDown="document.myForm.button1.value='Thank You!'"><br><input type=button id="button2" value="Fade the text box"  onMouseOver="mOvr('myText','#996633','#cccc99',10,40)"  onMouseOut="mOut('myText','#996633','#cccc99',10,40)"  onMouseDown="document.myForm.button2.value='Gracias!'"><br><input type=button id="button3" value="Fade this page"  onMouseOver="mOvr('myPage','#ffffff','#758642',10,100)"  onMouseOut="mOut('myPage','#ffffff','#758642',10,100)"  onMouseDown="document.myForm.button3.value='Merci!'"><br></div></form><div align="center" id="myText" style="border: 3px solid #c0c0c0; display: block; width: 250; background-color: #996633; padding: 4px;">Text Box<br><br>Free JavaScripts provided by<br>The JavaScript Source </div><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->