Got a funny bit of javascript

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jan 2007
Posts: 11
Reputation: james_eblin is an unknown quantity at this point 
Solved Threads: 0
james_eblin's Avatar
james_eblin james_eblin is offline Offline
Newbie Poster

Got a funny bit of javascript

 
0
  #1
Jan 30th, 2007
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);
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Got a funny bit of javascript

 
0
  #2
Jan 31st, 2007
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)
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 11
Reputation: james_eblin is an unknown quantity at this point 
Solved Threads: 0
james_eblin's Avatar
james_eblin james_eblin is offline Offline
Newbie Poster

Re: Got a funny bit of javascript

 
0
  #3
Feb 1st, 2007
Thanks, Thats really helpful, i just wanted yo know so i could play with integers
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 5
Reputation: James1997123 is an unknown quantity at this point 
Solved Threads: 0
James1997123 James1997123 is offline Offline
Newbie Poster

Re: Got a funny bit of javascript

 
0
  #4
Jan 3rd, 2009
Originally Posted by james_eblin View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC