The goal is to have a div grid run up and color in the page
1 <style>2 * {3 margin:0px;4 padding:0px;5 }6 7 #DIV1{8 position:relative;9 width:50px;Ten Height:50px; One Background-color:Red; A } - </style> - </Head> the <Body> - <formID= "Form1"runat= "Server"> - <DivID= "DIV1"></Div> - </form> + </Body> - </HTML> + <Script> A varC= NewArray ();//defines an array placement color at c[0] = 'Green'; - c[1] = 'Yellow'; - c[2] = 'Black'; - c[3] = 'Navy'; - c[4] = 'Blue'; - c[5] = 'Red'; in varNum= 0;//sets a variable to record the number of times the color changes and the index of the color in the array - varNUM1= 0;//set several variables to record the number of times the function was executed to varDiv=document.getElementById ('DIV1');//Get Div + functionF () { - if(NUM1% Ten == 0) {//control the speed of color change the Div.style.backgroundColor=C[num];//Change Color * Num++; $ if(Num==c.length) {Panax Notoginseng Num= 0;//re-record the number of changes in color when the array length reaches zero - } the } + Div.style.left=Div.offsetleft+ Ten + 'px';//Div moves 10 pixels across the landscape A if(Div.offsetleft> 1300) {//move 1300 pixels when line breaks plus transverse position zeroing the Div.style.left= 0 + 'px'; + Div.style.top=Div.offsettop+ - + 'px'; - } $ if(Div.offsettop> -) {//The div goes back to the origin when it reaches 500 vertically. $ Div.style.left= 0 + 'px'; - Div.style.top= 0 + 'px'; - } the NUM1++; - }Wuyi Window.setinterval ('F ()', -);//execute function once every 20 milliseconds the </Script>
A little practice of JS