Is this code ok ?

B

bieling

Hello,

That's the first time ever I write code in javascript.
I've put a large background picture, much larger than the window, and
set "background-repeat: repeat" to show it in a 'mosaic' fashion.
I intend to animate the background by shifting it's position every few
seconds. As the image is much larger than the window, it will
(hopefully) look like a different background image.

I try to make the shift take place in two steps, the first one fast
enough to be noticed and then a second last one. Later on I'm going to
add a sound, I'm attempting to make it look like a microfilm being
moved around in a microfilm viewer.

<script language="JavaScript">
var ID1 = window.setInterval(function(){fondo()
+window.setTimeout('fondo()',90);},2500)
function fondo()
{document.body.style.backgroundPosition=(Math.random()*100)+'% '+
(Math.random()*100)+'%';}
</script>

I've also put this:

<body onunload="window.clearInterval(ID1); (..)

Because sometimes when exiting/comingBak to the page, the background
animation was accelerating.

There's a small animated gif on the top of the page that slows down a
lot on some browsers during the background animation, but at random
intervals. I'm not sure if it has to do with this code, but I guess
so.

I know the code is working, but I'm not sure if it's ok. What do you
think ?

In case you want to see it the url is :
<http://homepage.mac.com/jorgechamorro/a2things/>

Thanks,
--Jorge.
 
S

shimmyshack

Hello,

That's the first time ever I write code in javascript.
I've put a large background picture, much larger than the window, and
set "background-repeat: repeat" to show it in a 'mosaic' fashion.
I intend to animate the background by shifting it's position every few
seconds. As the image is much larger than the window, it will
(hopefully) look like a different background image.

I try to make the shift take place in two steps, the first one fast
enough to be noticed and then a second last one. Later on I'm going to
add a sound, I'm attempting to make it look like a microfilm being
moved around in a microfilm viewer.

<script language="JavaScript">
var ID1 = window.setInterval(function(){fondo()
+window.setTimeout('fondo()',90);},2500)
function fondo()
{document.body.style.backgroundPosition=(Math.random()*100)+'% '+
(Math.random()*100)+'%';}
</script>

I've also put this:

<body onunload="window.clearInterval(ID1); (..)

Because sometimes when exiting/comingBak to the page, the background
animation was accelerating.

There's a small animated gif on the top of the page that slows down a
lot on some browsers during the background animation, but at random
intervals. I'm not sure if it has to do with this code, but I guess
so.

I know the code is working, but I'm not sure if it's ok. What do you
think ?

In case you want to see it the url is :
<http://homepage.mac.com/jorgechamorro/a2things/>

Thanks,
--Jorge.

the effect is a nice idea. You might be able to acheive a smooth
transition using a div styled to have z index below the rest of the
body content, and use one of the transition effects that libraries
like scriptaculous.js provide.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top