skripter
06-10-2007, 04:51 AM
In my attemtp to learn more about coding I am now looking at working scripts and trying to understnad their code lines.
Often I encounter code lines that are new to me and do not understand.
The following is a partial script I extracted and am trying to understand:
I hope the script experts on this site may be able to answer any of the following questions.
<script id="script" type="text/javascript">
// <![CDATA[
why is the id="script" necessary?
What does the [CDATA[ mean? I haven't seen this before.
var speed=5; // lower number for faster
var flakes=150; // number of flakes
var colour="FFFAFA"; // colour of flakes
var slush=0; // set to '0' for no slush or otherwise set to height at which slush melts
/***************************\
\* DON'T EDIT BELOW THIS BOX *
\***************************/
var flks=new Array();
var flkx=new Array();
var flky=new Array();
var fldy=new Array();
var slss=new Array();
var slsh=new Array();
var swide, shigh;
6 variables were created or defined yet their elements were not specified. In all the tutorials I have seen online about arrays, they all showed that whenever an array is used their elements are also indicated. Where are the arrays' elements?
window.onload=function startsnowingdo() { if (document.getElementById) {
var b, s;
b=document.createElement("div");
s=b.style;
s.position="absolute";
b.setAttribute("id", "bod");
document.body.appendChild(b);
set_scroll();
set_width();
for (var i=0; i<flakes; i++) {
flks[i]=createDiv(1, 1);
flkx[i]=3*Math.floor(Math.random()*swide/3);
flky[i]=Math.floor(Math.random()*shigh);
fldy[i]=2+Math.floor(Math.random()*4);
flks[i].style.left=flkx[i]+"px";
flks[i].style.top=flky[i]+"px";
b.appendChild(flks[i]);
}
Can you explain please what this function does or accomplishes? Are they defining or creating the arrays' elements within this function?
setInterval("let_it_snow()", speed);
}}
function createDiv(height, width) {
var div=document.createElement("div");//Are they creating a div element? div.style.position="absolute";
div.style.height=height+"px";
div.style.width=width+"px";
div.style.overflow="hidden";
div.style.backgroundColor=colour;
return (div);
}
what does this function accomplish? What value does it return?
Thanks much
Often I encounter code lines that are new to me and do not understand.
The following is a partial script I extracted and am trying to understand:
I hope the script experts on this site may be able to answer any of the following questions.
<script id="script" type="text/javascript">
// <![CDATA[
why is the id="script" necessary?
What does the [CDATA[ mean? I haven't seen this before.
var speed=5; // lower number for faster
var flakes=150; // number of flakes
var colour="FFFAFA"; // colour of flakes
var slush=0; // set to '0' for no slush or otherwise set to height at which slush melts
/***************************\
\* DON'T EDIT BELOW THIS BOX *
\***************************/
var flks=new Array();
var flkx=new Array();
var flky=new Array();
var fldy=new Array();
var slss=new Array();
var slsh=new Array();
var swide, shigh;
6 variables were created or defined yet their elements were not specified. In all the tutorials I have seen online about arrays, they all showed that whenever an array is used their elements are also indicated. Where are the arrays' elements?
window.onload=function startsnowingdo() { if (document.getElementById) {
var b, s;
b=document.createElement("div");
s=b.style;
s.position="absolute";
b.setAttribute("id", "bod");
document.body.appendChild(b);
set_scroll();
set_width();
for (var i=0; i<flakes; i++) {
flks[i]=createDiv(1, 1);
flkx[i]=3*Math.floor(Math.random()*swide/3);
flky[i]=Math.floor(Math.random()*shigh);
fldy[i]=2+Math.floor(Math.random()*4);
flks[i].style.left=flkx[i]+"px";
flks[i].style.top=flky[i]+"px";
b.appendChild(flks[i]);
}
Can you explain please what this function does or accomplishes? Are they defining or creating the arrays' elements within this function?
setInterval("let_it_snow()", speed);
}}
function createDiv(height, width) {
var div=document.createElement("div");//Are they creating a div element? div.style.position="absolute";
div.style.height=height+"px";
div.style.width=width+"px";
div.style.overflow="hidden";
div.style.backgroundColor=colour;
return (div);
}
what does this function accomplish? What value does it return?
Thanks much