Hey, my friend sent me this funny java script, if you copy and paste it in the adress bar and hit enter it makes the links spin around, any one know how this works?

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=2.6; y3=.24; x4=100; y4=100; x5=300; y5=300; DI=document.getElementsByTagName("img"); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+ "px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+" px"}R++}setInterval('A()',5); void(0);

Well it declares some variables R=0; x1= blah y1=blah...
Then where it starts 'DI' that's an array of images on the page (DI probably for DocumentImages) document.getElementsByTagName("img") returns an array of references to every img object in the DOM (Document Object Model). DIL is the length of DI so that's the count of the images found in the page, A function is then created that loops through the image list, gets the style attribute of each one and changes its css positioning in the dom. Finally function A is called using the built in javascript function setInterval which continuously runs function A every 5 (I think milliseconds i'm not sure of the units without looking it up)

Thanks, Thats really helpful, i just wanted yo know so i could play with integers

Hey, my friend sent me this funny java script, if you copy and paste it in the adress bar and hit enter it makes the links spin around, any one know how this works?

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=2.6; y3=.24; x4=100; y4=100; x5=300; y5=300; DI=document.getElementsByTagName("img"); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+ "px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+" px"}R++}setInterval('A()',5); void(0);

If you look carefully in the above code, its rotating the HTML “img” tag. You can also replace it with “a” or “p” and watch some links or text rotate instead of images.

This question has already been answered. Start a new discussion instead.