Weird behaviour with falling snow script

T

toronto

I'm stumped. I'm playing with a javascript that produces falling snowflakes
on screen. I got the script from this author:
http://thelocust.org/projects/snow2/

If I hotlink to the exploding flake image on the author's site, everything
works as intended: clicking a flake explodes it once, and at some point a
new white flake is produced at the top of the screen to replace the exploded
one.

However, if I save his exploding image to my own web directory and link to
it, as my second test, then clicking a flake causes it to explode
indefinitely in a repeating loop. Bizarre.

Third test, I edited the GIF to not loop it and to end on a blank
transparent frame, so that a flake will explode only once. The problem here
is that after you explode some flakes, they are never replaced by new ones.
No new white flakes appear. In fact, I think the images are still floating,
but it's always the final blank frame of my edited exploding image. Those
are never replaced by the white flake image.

See if you can figure this one out. What I want is the behaviour in Test 1,
but using a local file of the exploding image rather than having to hotlink
to the file off the author's site.

See my tests here: http://public.fiercefocus.com/SnowTests/
 
V

VK

As much as I can see the explosion and the flake are two different
pictures.
onClick static flake gif is being replaced/z-overdrawn (have no time to
check) by animated explosion gif. Read instructions with more attention.
Should help...
 
T

toronto

VK said:
As much as I can see the explosion and the flake are two different
pictures.

Yes, I know. I said that in my tests at
http://public.fiercefocus.com/SnowTests/
Read instructions with more attention.
Should help...

Your smug answer doesn't help anyone. As you would see from my tests and my
descriptions on those pages, I did follow the instructions. My Test 1 works
fine, but requires me to hotlink to someone else's file.

The only difference is where the explosion image resides. If I link to the
file on the author's web site, everything works fine. If I link to that same
image saved to my own web directory, it doesn't work properly. There are no
changes to the script other than where that image lives. For some reason it
doesn't work properly if the image sits on my web server or on my PC, but
works if I link to the author's file.
 
R

Richard Cornford

Fabian said:
I tried looking at the demo on teh original author's page, and
it came up with a fatal error. I suspect it is the original
author who needs help, not you.

That is certainly the case as the script includes:-

snowobj = eval (document.getElementById("flake"+i).style);

-and much else that demonstrates a limited understanding of JavaScript
and browser scripting.

However, the OP's problem is with the line;-

if (document.getElementById('imgflake' + i).src == imgExplode) {

- which compares the src attribute of an image element with the value
assigned to - imgExplode -. But the src attribute of an image element
becomes an absolute URL even when set with a string that represents a
relative URL, as is the case in the examples that use images from the
OP's server, but not when linking to the images on another server as
that URL needs to be absolute anyway. A quick fix would be to change the
test to see if the contents of the - imgExplode - variable was a
substring of the image element src string:-

if(document.getElementById('imgflake'+i).
src.lastIndexOf(imgExplode) >= 0){

Though that would not help with all relative URLs (e.g.
"../../Images/Snow.gif").

It would probably be best to have the script implemented by someone who
know what they were doing.

Richard.
 
T

toronto

That is certainly the case as the script includes:-

snowobj = eval (document.getElementById("flake"+i).style);

-and much else that demonstrates a limited understanding of JavaScript
and browser scripting.

However, the OP's problem is with the line;-

if (document.getElementById('imgflake' + i).src == imgExplode) {

- which compares the src attribute of an image element with the value
assigned to - imgExplode -. But the src attribute of an image element
becomes an absolute URL even when set with a string that represents a
relative URL, as is the case in the examples that use images from the
OP's server, but not when linking to the images on another server as
that URL needs to be absolute anyway. A quick fix would be to change the
test to see if the contents of the - imgExplode - variable was a
substring of the image element src string:-

if(document.getElementById('imgflake'+i).
src.lastIndexOf(imgExplode) >= 0){

Though that would not help with all relative URLs (e.g.
"../../Images/Snow.gif").

It would probably be best to have the script implemented by someone who
know what they were doing.

Richard.


Thanks for checking. I didn't know his script had so many errors.

I don't write javascript, but I want a snow fall effect for an on-line
family card. I searched at some script archives: I found several snow
scripts, but all had defects or errors or choked in modern browsers. This
one seemed to mostly work in modern browsers. This one seems to be pretty
good, if the errors were corrected.

I don't suppose anyone knows where I can find an error-free snowfall script?
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top