260 likes | 339 Views
Drop-down list and timers. Double click on the drop-down list icon to place one on the page. Change the name and id attributes. Use the Style Builder dialog box to select a background color. Use the Style Builder dialog box to set the width.
E N D
Double click on the drop-down list icon to place one on the page.
Use the Style Builder dialog box to select a background color
Enter expressions into the Text and Value textboxes and click Insert to place data into list.
Click in the general document (on the page but not in the div or the drop down list) and click on the bgcolor attribute
Choose a color (I chose black – yeah I know it’s not really a color)
Body code <script> var timerID=setInterval("RenderShape()",1000); </script> This code establishes a timer that “raises” a timer event every 1000 milliseconds (every second). It calls the RenderShape function that is placed in the head.
Head code <script> function RenderShape() { alert("HI"); } </script> A function that display a message HI. It will be called every second.
Revised RenderShape() – part 1 var AngleOffSet=0; function RenderShape() { var RectHTML; var XCenter = 300; var YCenter = 300; var PI=Math.atan(1)*4; var Angle; var Radius= 200; var XPosition; var YPosition;
Revised RenderShape() – part 2 AngleOffSet = AngleOffSet - 5; Angle = (AngleOffSet)*2*PI/360; XPosition=XCenter+Radius*Math.cos(Angle); YPosition=YCenter+Radius*Math.sin(Angle); RectHTML="<div style=\"height: 60px; width: 40px; position: absolute; top:"+YPosition+"px; left: "+XPosition+"px; background: #FFFFFF\" ms_positioning=\"GridLayout\"></div>"; MyDiv.innerHTML = RectHTML; }
Faster, faster. • var timerID=setInterval("RenderShape()",100); • Lower the number in the setInterval function to make the circle move around faster.
AngleOffSet = AngleOffSet - 5; MyDiv.innerHTML=""; for(i=15; i>=0; i--) { Angle = (AngleOffSet+i*i)*2*PI/360; XPosition=XCenter+Radius*Math.cos(Angle); YPosition=YCenter+Radius*Math.sin(Angle); RectHTML="<div style=\"height: 60px; width: 40px; position: absolute; top:"+YPosition+"px; left: "+XPosition+"px; background: #FFFFFF\" ms_positioning=\"GridLayout\"></div>"; MyDiv.innerHTML += RectHTML; }
Introduce code to change color of rectangles MyColor=(255-17*i).toString(16)+(255-17*i).toString(16)+(255-17*i).toString(16); RectHTML="<div style=\"height: 60px; width: 40px; position: absolute; top:"+YPosition+"px; left: "+XPosition+"px; background: #"+MyColor+"\" ms_positioning=\"GridLayout\"></div>";
for(i=15; i>=0; i--) { switch(selShape.value) { case "circ": Angle = (AngleOffSet+i*i)*2*PI/360; XPosition=XCenter+Radius*Math.cos(Angle); YPosition=YCenter+Radius*Math.sin(Angle); break; case "card": Angle = (AngleOffSet+i*i)*2*PI/360; Radius = 200*(1+Math.cos(Angle)); XPosition=XCenter+Radius*Math.cos(Angle); YPosition=YCenter+Radius*Math.sin(Angle); break;
case "astr": Angle = (AngleOffSet+i*i)*2*PI/360; XPosition=XCenter+Radius*Math.cos(Angle)*Math.cos(Angle)*Math.cos(Angle); YPosition=YCenter+Radius*Math.sin(Angle)*Math.sin(Angle)*Math.sin(Angle); } }