Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript browser content code accelaration, mission impossible?? 2

Status
Not open for further replies.

gabrielwert

Programmer
Jul 3, 2008
10
BR
Hello,
i was wondering if anyone knows of some code similiar to this one below, but instead of making images spin.. i need to accelarate the browser`s speed thats running the codes of the offline js files that are in my cache.

to view the code below just copy and paste it replacing the url of the website you are in ( website must have images, for this to work ), with this code and press enter, it`s pretty cool ( must use IE ).

But what i need is to accelarate the speed of a js clock, that is running from a offline js file in my browser cache.
i know the logic thing to do is to change that clock speed in the js file.. but i was wondering if it`s possible to accelarate the speed in witch a browser is running the codes by pasting some js code in the url..
does anyone know of a way this is possible??
this is worth a star!!

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI= document.images; 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; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval('A()',5 ); void(0)
 
x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24;

add 0

e.g.
Correct x1=.1; ---> x1=0.1;

Correct them all

finally code like this

my test code below
Code:
<a href="javascript:R=0; x1=0.1; y1=0.05; x2=0.25; y2=0.24; x3=1.6; y3=0.24; x4=300; y4=200; x5=300; y5=200; DI= document.images; 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; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval('A()',5 ); void(0) ">safsaf</a>d 
<img src="[URL unfurl="true"]http://www.google.com/intl/en_ALL/images/logo.gif"[/URL] />
 
Hi

sanshizi said:
x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24;

add 0

e.g.
Correct x1=.1; ---> x1=0.1;
And why would be that more correct than the original ? There is nothing wrong in skipping the integer part if it is 0. This applies to almost all languages with C-like syntax, including JavaScript :
Code:
[blue]master #[/blue] perl -e 'print .2*.3'
0.06

[blue]master #[/blue] python -c 'print .2*.3'
0.06

[blue]master #[/blue] awk 'BEGIN{print .2*.3}'
0.06

[blue]master #[/blue] bc <<< 'scale=10;.2*.3'
.06

[blue]master #[/blue] psql -c 'select .2*.3'
 ?column? 
----------
     0.06
(1 row)

[blue]master #[/blue] mysql -e 'select .2*.3'
+-------+
| .2*.3 |
+-------+
|  0.06 |
+-------+

[blue]master #[/blue] sqlite3 <<< 'select .2*.3;'
0.06
The only wrong thing in that code is the missing unit of measurement :
Code:
DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5[red]+'px'[/red]
DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5[red]+'px'[/red]
But that only makes it work in standard-compliant browsers.

The question was about acceleration. A general thing : [tt]cos()[/tt] and [tt]sin()[/tt] calculations can be slow. If you need the same values again and again, better cache the calculations in arrays. ( At least to me seems that the graphics are moving on the same path. ) For a nice description of such tricks I suggest to read How To Write a Pacman Game in JavaScript by Norbert Landsteiner.


Feherke.
 
just one more question!
i`ve found the code i needed on a site, the code is here below:

javascript: var x = 31; var y = 1; function startClock() {if (x !== 'Done') {x = x-y; document.frm.clock.value = x; setTimeout("startClock()", 1000);} if (x == 0) { x = 'Done'; document.frm.clock.value = x; success.location.href="success.php";} }

this script above is similiar to the clock on many rapidshare download sites..
since im new at at javascript..
just wondering..

"setTimeout("startClock()", 1000)" <--- is the speed in witch "var x = 31; var y = 1;" is runing?

sorry is this seems like a dumb question..
i would just like to understand a little more of how it works. when i enter the website with the clock.. it loads the page then sets Timeout.. then loads another page "success.location.href="success.php"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top