javascript - variable should not grow -


i'm struggling quite long time strange problem in javascript. do:

  1. collecting elements html code
  2. change order randomly , 'put them back'

i compute each position of divs getting height , adding offset. variable 'toppos' going crazy. everytime function gets evaluated not reset. instead grows , grows. site becomes quite glitchy in nice way. time want work in right way.. ( : can help? thanks.

here code:

function setpos(){   var vidarray = shuffleframes();   var toppos = 30;   var prevheight = 0;   for(var = 0; < vidarray.length; i++){     var element = vidarray[i];     element.style.top = toppos.tostring() + "px";     prevheight = $(vidarray[i]).height();     toppos = toppos + prevheight + 15;     element.style.display = "block";     }; toppos = 30; };     

it gets called function:

function randstart(){   var elem = document.getelementsbyclassname("videofont");   getelements(elem);   setpos(); }; 

here html-part:

div id="p00" class="videofont" > <iframe src="some video" ></iframe>   </div>  div id="p01" class="videofont" > <iframe src="some video" ></iframe>   </div>  div id="p02" class="videofont" > <iframe src="some video" ></iframe>   </div>  " … , on "  

the remove function :

function rempos(){   var vidarray = frames;   for(var i=0; i<frames.length; i++){     var element = vidarray[i];     element.style.display = "none";     $(element).removeattr('style');    }; };     

the rest:

function shuffleframes() {   var currentindex = frames.length,     temporaryvalue, randomindex;   while (0 !== currentindex) {     randomindex = randomizer(currentindex);     currentindex -= 1;     temporaryvalue = frames[currentindex];     frames[currentindex] = frames[randomindex];     frames[randomindex] = temporaryvalue;   };    return frames; };   var frames = []; function getelements(elements){   for(i = 0; < elements.length; i++){     frames.push(elements.item(i));   }; }; 

the css .videofont sais: .videofont { position:absolute; left:400px; top:300px; z-index:999; display:none; }

thanks!


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -