Antje Hofmann: wachsender balken - Lösung

Beitrag lesen

Hi vmx,

war nur eine Kleinigkeit, wirst es ja selbst finden :-)

<html>
<head>
<title>Farbbalken</title>
<style type="text/css">
<!--
#bal {position:absolute;top:10;left:10;width:240;height:10;border:thin;}
#farbe {position:absolute;top:30;left:10;width:200;height:20;border:solid;}
#zahl {position:absolute;top:70;left:10;width:200;height:20;border:solid;}

//-->
</style>
<script language="JavaScript">
<!--
var a = Math.random();
   a = a*255;
   a = Math.ceil(a);
   d = a;
   i=0;

function Balken()
  {

{i++;
      if(i<30)
        {
         var z = "#00ff00" ;
        }

else  if(i<128)
              {
               var b = i*2;

var red = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
               var redhex1 = b/16;
                redhex1 = Math.floor(redhex1);
               var redhex2 = b%16;

var z = "#" + red[redhex1] + red[redhex2] + "ff00";
             }

else
              {
               var c = 511-(i*2);

var neggreen = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
               var neggreenhex1 = c/16;
                   neggreenhex1 = Math.floor(neggreenhex1);
               var neggreenhex2 = c % 16;

var z = "#ff" + neggreen[neggreenhex1] + neggreen[neggreenhex2] + "00";
              }

if (document.all) /*IE-Syntax*/
        {
         document.all.bal.style.width=2*i;
         document.all.bal.style.backgroundColor=z;
         document.all.farbe.innerText=z;
         document.all.zahl.innerText=d;
        }
      else
        { /*Navi-Syntax*/
         document.bal.bgColor=z;
         document.bal.resizeTo(2*i,10);
         document.farbe.document.open();
         document.farbe.document.write(z);
         document.farbe.document.close();
         document.zahl.document.open();
         document.zahl.document.write(d);
         document.zahl.document.close();
        }
     }
if (i<a) setTimeout("Balken()",300);}

//-->
</script>
</head>
<body onLoad="Balken()">
<div id="bal"> </div>
<div id="farbe"> </div>
<div id="zahl"> </div>
</body>
</html>

Viele Grüße

Antje